Winsock functions lock/stall up program

Pages: 12
thats what i figured. Can i make a socket array with a max number of sockets as the initialization value. You would have to be able to do that or you would have to hand initialize every single socket which would mean typing socket over and over again. Also...can i have client connect to server on multiple sockets. I mean server can have multiple client sockets. So i dont see why client couldn't connect with multiple different sockets.

The reason i ask is because it would be easier to send specific types of data over each socket rather then sending every type of data over one socket. Then you have to check what kind of data it is and check if all of it was received. However if you have different sockets on client side to send different types of data on in a sequential order you wouldn't have to check to see what was being sent because you know that socket is only sending a certain type of data....whether that data represents player coordinates or whether it represents commands or represents events ect. you would still have to have code in place to check what it was in some instances but you could circumvent alot of headache and error by having client connect on multiple sockets.

also can you use WSAAsyncSelect() on client side? if you could that would be excellent...if not then recv() is just gonna block unless you put it in a timer and even then if recv() is not synchronized with the incoming data i imagine you would miss it.

also im not seeing how you would set up each socket as non blocking using WSAAsyncSelect() if you have 100's of sockets seeing as each call to WSAAsyncSelect cancels out the last call to it...unless there is something i am misunderstanding. whats the point of having a server that can only have one non blocking socket. thats like a chat company only being able to provide service to one person...lol who would you chat with?

nvrmind i guess whenever you call WSAAsyncSelect() with the listening socket specified then eveytime you get a request you would bind it to a new client socket using the accept() function then the new client socket would inherit the non blocking capabilities of the listening socket. Because my client socket inherited the non blocking properties when i called accept() with the non blocking listening socket specified as the socket i was accepting.

So my only debacle now is...can i make socket arrays for easy mass creation of sockets and can i use WSAAsyncSelect on client side...or is there a more effecient way to recv on client side without blocking than by using timer function. if the socket is setup as non bocking on client side then you would have to make the client a semi client-server combo i think. cause the way i understand WSAA goes after the listen function....and clients dont have listen function....maybe i could put it after connect() function.
Last edited on
Can i make a socket array with a max number of sockets as the initialization value

Nothing's stopping you from doing that. You could even have a vector of sockets in case you don't know how many sockets you're going to initialize beforehand.

Also...can i have client connect to server on multiple sockets...The reason i ask is because it would be easier to send specific types of data over each socket rather then sending every type of data over one socket.

Yes, you can have a client connected to the same server through multiple sockets, however this can get a bit dicey. On the server side, all it sees is an incoming connection, so you would have to setup some kind of identification process. You could have the client randomly give itself an ID (like a GUID: see below) at startup. When the client connects with the server with the first socket, the server would look up this ID and see if the ID has been used before. If not, the server would assign this particular socket to be the first socket from this client. When the client connects again through a different socket, the server would look up the ID and see that this client already has one socket open, so the server would assign this particular socket to be the second socket from this client, and so on.

Problems could occur of course if one client is using the ID of another. To circumvent this, you could have the server generate the ID. However, the handshaking process would be more involved because the client would have to then receive the ID. If the client already has an ID, it should send back to the server the fact that it already has an ID as well as what it is (if the client doesn't have an ID, it could send back -1 for example). Then, the server would be able to figure out that this is socket N from this particular client (if it received -1 then this would be connection 1).

You may find that this whole ID generation and look up business is too much overhead. If so, you could prepend a code to the message from the client, so that the server has a heads up as to what's coming. For instance, you could reserve the first 2 bytes of the message and have the code be an unsigned short (this will give you 65536 possible messages).

http://en.wikipedia.org/wiki/Globally_unique_identifier

also im not seeing how you would set up each socket as non blocking using WSAAsyncSelect() if you have 100's of sockets seeing as each call to WSAAsyncSelect cancels out the last call to it

You answered your own question on that one (when you call WSAAsyncSelect you pass in a socket, and that's the socket whose previous WSAAsyncSelect call gets cancelled).

also can you use WSAAsyncSelect() on client side?

I'm unsure about this but my first instinct is you can't. Using WSAAsyncSelect requires a call to listen, which in turn requires a bind, which means that it's a server socket. There may be other options out there that allow a client-side socket to use genuine non-blocking calls, however. Also, nothing's stopping you from having a "client" set up a server socket and having it tell the server the connection info of that socket through an already established socket (you'll be setting up a kind of P2P network in this case).

or is there a more effecient way to recv on client side without blocking than by using timer function.

After the client establishes the socket, you can start a thread that just calls recv and then forwards the data in an infinite loop.
Topic archived. No new replies allowed.
Pages: 12