Jump to content
  • Advertisement
Sign in to follow this  

http server functioning concept

This topic is 2748 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi gamedev crews and members,

i need some help from u guys regarding winsock http server concept.

basically, what i understood is like below.

1. WSAStartup
2. create listening socket
3. bind socket
4. start listening

then after this i kinda blur.

i try mimic my http server based on some MSDN sample code,
usually they create another socket so that to accept the connection.

then they go into while ( TRUE )
a). accept function
b). WSARecv
c). WSAWaitForMultipleEvents
d). WSAGetOverlappedResult
e). WSAResetEvent

like above, only change a). to send function.

just kinda mind boggling how to make it handle more than 1 client connection :(

please insight me, thank you.

Share this post

Link to post
Share on other sites

just kinda mind boggling how to make it handle more than 1 client connection :(

Typically, you want to keep a set of all the sockets that you have seen, and wait on all of them at the same time.
You do not want to use WSAAsyncSelect() or similar. Instead, you want to do one of the following:
1) Use select() on all the sockets, and recv()/send() the sockets that say they are ready. Your listening socket is one of these sockets; when it says it's ready, you can call accept() without blocking. This is portable, and very similar to how it's done on UNIX.
2) Use I/O completion ports, and OVERLAPPED I/O on the socket handles. Use GetQueuedIoCompletionStatus() from within one or more threads to dequeue work to do for the different sockets. This is not particularly portable outside Win32, but it's very high performance when you have thousands of sockets.

Another option is to use boost::asio for your sockets code. It's portable C++ that uses the most efficient mechanism for each OS (linux, bsd, win32, etc).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!