CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2005
    Location
    Akron, Ohio
    Posts
    670

    Unhappy WSAAsyncSelect, Multiple sockets

    I'm trying to upgrade an old Windows application I created long ago so that it will now support up to 7 sockets for LAN use. I've been reading up on the Windows Sockets and I've seen numerous tutorials and samples. The one question that I haven't seen an answer to is this: Can you call WSAAsyncSelect once for each socket?

    for example:
    Code:
    errorint1 = WSAAsyncSelect(Socket1, MyWindowHND, SOCKET1_EVENT, FD_READ | FD_WRITE);
    errorint2 = WSAAsyncSelect(Socket2, MyWindowHND, SOCKET2_EVENT, FD_READ | FD_WRITE);
    errorint3 = WSAAsyncSelect(Socket3, MyWindowHND, SOCKET3_EVENT, FD_READ | FD_WRITE);
    errorint4 = WSAAsyncSelect(Socket4, MyWindowHND, SOCKET4_EVENT, FD_READ | FD_WRITE);
    errorint5 = WSAAsyncSelect(Socket5, MyWindowHND, SOCKET5_EVENT, FD_READ | FD_WRITE);
    errorint6 = WSAAsyncSelect(Socket6, MyWindowHND, SOCKET6_EVENT, FD_READ | FD_WRITE);
    errorint7 = WSAAsyncSelect(Socket7, MyWindowHND, SOCKET7_EVENT, FD_READ | FD_WRITE);
    Thanks all.
    error C2146a : syntax error : nebulizer stained in the tower floppy apple rider. Go rubble in flee smite. Bleeble snip snip.

    Documentation says: error C2146a - This means there is an error somewhere in the course of human endeavor. Fix in the usual way.

  2. #2
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: WSAAsyncSelect, Multiple sockets

    Can you call WSAAsyncSelect once for each socket?
    I don't fully understand the question. Do you mean: "Is it enough to call WSAAsyncSelect only once per socket"? If so, then the answer is "yes".

    I'm trying to upgrade an old Windows application I created long ago so that it will now support up to 7 sockets for LAN use
    What is the significance of the number 7 as a limit? In many applications (both client and server) there is no explicit limit or the limit is very high. For example, a client is permitted to make as many connections as it want s to as many servers as it wants, and a server is permitted to accept connections from as many clients as it can until errors (out of memory etc) start cropping up. A limit like "7" is odd.

    Mike

  3. #3
    Join Date
    Jan 2005
    Location
    Akron, Ohio
    Posts
    670

    Resolved Re: WSAAsyncSelect, Multiple sockets

    Well, I'm having trouble understanding how to deal with the messages that come from WSAAsyncSelect. By the time they reach the windows routing system and I handle the message, I don't know which socket the message came from. Can this be deciphered this from wParam or lParam??

    The only thing I could think of was to assign 7 sockets ahead of time with their own message (SOCKET_EVENT1, SOCKET_EVENT2, etc.) and call WSAAsyncSelect for each. When my handler for OnSocketEvent1 was called, I would know that it involved the Client assigned to socket 1. I chose "7" sockets because 7 clients plus 1 server equals 8 computers, which is the amount I can support on my router.

    However, before I could do any of this, I wanted to make sure I could make multiple calls to WSAAsyncSelect, privided that each call was for a different socket. I had some suspicions that multiple calls to WSAAsyncSelect negated previous calls, even if the other calls were for different sockets.

    for example:
    Code:
    WSAAsyncSelect(socket_1, . . .);    // socket_1 is WSAAsyncSelect()'ed
    WSAAsyncSelect(socket_2, . . .);    // socket_2 is WSAAsyncSelect()'ed, but now socket_1 is no longer WSAAsyncSelect()'ed
    At any rate, can I resolve which socket the event is occuring on from lParam or wParam?
    error C2146a : syntax error : nebulizer stained in the tower floppy apple rider. Go rubble in flee smite. Bleeble snip snip.

    Documentation says: error C2146a - This means there is an error somewhere in the course of human endeavor. Fix in the usual way.

  4. #4
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: WSAAsyncSelect, Multiple sockets

    I'm having trouble understanding how to deal with the messages that come from WSAAsyncSelect. By the time they reach the windows routing system and I handle the message, I don't know which socket the message came from. Can this be deciphered this from wParam or lParam??
    Yes, the identity of the socket is carried in the wParam for the message. You can use the wParam directly, in calls to Winsock functions, e.g.:

    recv(wParam, ...);

    The lParam encodes the network event and any error codes, specifically, the low word of lParam specifies the network event that has occurred, and the high word of lParam contains any error code.

    See generally the documentation for WSAAsyncSelect at http://msdn.microsoft.com/en-us/libr...40(VS.85).aspx

    You should use the macros WSAGETSELECTERROR and WSAGETSELECTEVENT to extract the network event and the error code.

  5. #5
    Join Date
    Jan 2005
    Location
    Akron, Ohio
    Posts
    670

    Re: WSAAsyncSelect, Multiple sockets

    Excellent. Thanks MikeAThon!
    error C2146a : syntax error : nebulizer stained in the tower floppy apple rider. Go rubble in flee smite. Bleeble snip snip.

    Documentation says: error C2146a - This means there is an error somewhere in the course of human endeavor. Fix in the usual way.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured