Thread: Sockets idea?

  1. #1
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002

    Question Sockets idea?

    Hi guys, I'm trying to code a wrapper for asynchronous WinSock...

    What I have planned out so far:
    -function 'startup()' (in namespace 'Sockets') calls WSAStartup() and also starts a new thread
    -when the thread starts, it creates a new invisible window (for messages), the handle of which gets stored as a static variable
    -The thread starts up a GetMessage() loop

    -Any new ASocket will call WSAAsyncSelect using the invisible window's handle, and will add an entry to a static std::map container using its SOCKET descriptor as the key and a pointer to itself as the value. Also, it will be passed a HWND as a parameter, which will be stored for later use.

    -The message handler for the socket messages uses the static std::map to find the appropriate ASocket object and set its 'readable', 'writable', etc. variables to true. After this, it re-posts the message to the HWND stored in the object earlier, in case the user wants to handle the message him/herself as well.
    Is this a feasible way to write a sockets wrapper? Personally, I think this way is sort of clumsy, but I can't think of anything else. Any ideas? Input? My goal is to keep my wrapper class as a "Plug 'n Play" code module sort of thing, while still providing easy functionality. Does anyone have a better way of doing this, or does my plan sound O.K.?

    P.S. I posted on the Windows forum because of the stuff about threads and windows, etc. and also because nobody ever replies on the networking forum
    Last edited by Hunter2; 01-22-2004 at 03:44 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. inet_aton()... Noob needs help with sockets :|
    By Maz in forum C++ Programming
    Replies: 3
    Last Post: 11-22-2005, 04:33 PM
  2. Raw Sockets and SP2...
    By Devil Panther in forum Networking/Device Communication
    Replies: 11
    Last Post: 08-12-2005, 04:52 AM
  3. Have an idea?
    By B0bDole in forum Projects and Job Recruitment
    Replies: 46
    Last Post: 01-13-2005, 03:25 PM
  4. Asynchronous sockets
    By dpro in forum Networking/Device Communication
    Replies: 4
    Last Post: 12-20-2004, 06:53 PM
  5. Sockets
    By ober in forum C Programming
    Replies: 3
    Last Post: 03-16-2004, 10:47 AM