[Hugo Ferreira][Positronic Dreams][]
"Somewhere, something incredible is waiting to be known."
- Carl Edward Sagan (1934 - 1996)
Sockets-Server Programming
Hi all!
Doing some sockets programming in msvc++6.
Now, the receive function is a blocking one, correct?
There seems to exit a parameter that overides this...
My question is, how do we create a receive method
capable of receiving data from multiple clients... ?
...cause when we use receive, we must declare the client
we want to receive data from...
Ok, any help or links would be terribly useful,
Usually, when you create a server socket, you create a separate socket for each client. Thus you have to check each individual socket.
Using low level socket calls, this is the listen() function. It returns a new socket descriptor each time (for each client connection), then you call send/receive on that returned descriptor instead of the server socket.
Most programs will create a separate thread for each new connection, but there''s no reason why you couldn''t maintain a list and poll each one.
Using low level socket calls, this is the listen() function. It returns a new socket descriptor each time (for each client connection), then you call send/receive on that returned descriptor instead of the server socket.
Most programs will create a separate thread for each new connection, but there''s no reason why you couldn''t maintain a list and poll each one.
March 15, 2002 01:28 PM
quote:
Original post by cgoat
Usually, when you create a server socket, you create a separate socket for each client. Thus you have to check each individual socket.
Using low level socket calls, this is the listen() function. It returns a new socket descriptor each time (for each client connection), then you call send/receive on that returned descriptor instead of the server socket.
Most programs will create a separate thread for each new connection, but there''s no reason why you couldn''t maintain a list and poll each one.
I think you meant to say the ''accept'' function. The listen function is something quite different.
There are polling function you can use to find out when one of the sockets has something to say. Check out the select, function.
i''m trying to run away from the multiple-thread idea, one
thread per client connection...
Whats the usual aproach in game-programming?
thread per client connection...
Whats the usual aproach in game-programming?
[Hugo Ferreira][Positronic Dreams][]
"Somewhere, something incredible is waiting to be known."
- Carl Edward Sagan (1934 - 1996)
March 15, 2002 01:38 PM
quote:
Original post by pentium3id
i''m trying to run away from the multiple-thread idea, one
thread per client connection...
Whats the usual aproach in game-programming?
Assuming you don''t want to block at all -
Either one message handling thread per client, or nonblocking sockets that are periodically polled to see if anything''s in the buffer.
Any other option will just be built off of or a permutation of these.
quote:
Original post by Anonymous Poster
I think you meant to say the ''accept'' function. The listen function is something quite different.
Heh, yep. That''s what I meant. My point though was that each client connection ultimately gets its own socket. It''s up to the programmer to maintain and decide what to do with those sockets.
If you don''t want separate threads, then you have to do some sort of polling using either non-blocking sockets, or checking each socket using the select() method. I''d say select is probably a better idea.
Are you using a 3rd party class/library for sockets? Or are you just using the standard socket functions?
If your planning to use TCP over UDP take a look at I/O Completion Ports w/ Winsock. If your going to use UDP, take a look at I/O Completion Ports w/ Winsock. Catch the theme in those statements? There is a problem with IOCP and that is there isn''t much information available with respect to Winsock. But not to worry, I''ve found some good articles on the subject over at CodeProject.
HTH,
Dave "Dak Lozar" Loeser
HTH,
Dave "Dak Lozar" Loeser
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement