Creating an asynchronous socket server service

Started by
4 comments, last by humanapp 16 years, 5 months ago
Hi! I need to write a winsock-based server that is implemented as a windows service, using preferably C++, or optionally C++/CLI or C#. The server needs to listen for clients asynchronously, handle their requests (read and write from/to a database) and close the connection when a client disconnects (The clients will be Symbian devices, if that is of any help). I have done some basic blocking ping-pong socket programming before, but this is totally new to me. Are there any tutorials that could get me started? I found an asynchronous socket tutorial on gamedev, but it covered win32-apps, and my server needs to be implemented as a service. I appreciate any help you can give me, thanks! //chinc
Advertisement
Try the Forum FAQ. Note that "asynchronous sockets" in the way of going through the Windows event loop are fairly inefficient, although you can still use them. For example, you could create a message-only window handle, to use in the server.

I would probably use select() with the sockets, as usual. Select() allows you to write non-blocking code just fine, because select() tells you when a call to send() or recv() will not block.

If you find that the 64 simultaneous socket limit on select() becomes a problem, you can try using overlapped I/O on the sockets, and use I/O completion ports.
enum Bool { True, False, FileNotFound };
Is there still a 64 socket limit these days?

I wrote a small server app (with async sockets) a while ago and did a crude load test and had a couple of hundred clients connected at the same time.

It seemed to work ok. Was I just lucky? I was using 'Windows Server 2003' as my OS.
You can define FD_SETSIZE to be bigger on Windows (or UNIX) if you want to.
enum Bool { True, False, FileNotFound };
Thats wierd. I never did that.
For winsock-based asynchronous sockets, I/O completion ports are the way to go. I've seen IOCP perform extremely well under continuous heavy load, both with respect to the number of active sockets and the bandwidth over each one.

This topic is closed to new replies.

Advertisement