Sign in to follow this  
wuming

http server functioning concept

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

then
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
[quote name='wuming' timestamp='1302433727' post='4796627']
just kinda mind boggling how to make it handle more than 1 client connection :(

[/quote]

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this