• Advertisement
Sign in to follow this  

Creating an asynchronous socket server service

This topic is 3809 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! 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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


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

  • Advertisement