Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alternatives to winsock2 with example server source in c++

Tags:

c++

winsock

i'm using this example implementation found at http://tangentsoft.net/wskfaq/examples/basics/select-server.html

This is doing most of what I need, handles connections without blocking and does all work in its thread (not creating a new thread for each connection as some examples do), but i'm worried since i've been told winsock will only support max 64 client connectios :S

Is this 64 connections true?

What other choices do I have? It would be cool to have a c++ example for a similar implementation.

Thanks

like image 327
Joao Vilaca Avatar asked Jan 23 '23 22:01

Joao Vilaca


1 Answers

Alternative library:

You should consider using boost asio. It is a cross platform networking library which simplifies many of the tasks you may have to do.

You can find the example source code you seek here.


About the 64 limit:

There is no hard 64 connection limit that you will experience with a good design. Basically if you use some kind of threading model you will not experience this limitation.

Here's some information on the limit you heard about:

4.9 - What are the "64 sockets" limitations?

There are two 64-socket limitations:

The Win32 event mechanism (e.g. WaitForMultipleObjects()) can only wait on 64 event objects at a time. Winsock 2 provides the WSAEventSelect() function which lets you use Win32's event mechanism to wait for events on sockets. Because it uses Win32's event mechanism, you can only wait for events on 64 sockets at a time. If you want to wait on more than 64 Winsock event objects at a time, you need to use multiple threads, each waiting on no more than 64 of the sockets.

The select() function is also limited in certain situations to waiting on 64 sockets at a time. The FD_SETSIZE constant defined in winsock.h determines the size of the fd_set structures you pass to select(). It's defined by default to 64. You can define this constant to a higher value before you #include winsock.h, and this will override the default value. Unfortunately, at least one non-Microsoft Winsock stack and some Layered Service Providers assume the default of 64; they will ignore sockets beyond the 64th in larger fd_sets.

You can write a test program to try this on the systems you plan on supporting, to see if they are not limited. If they are, you can get around this with threads, just as you would with event objects.

Source

like image 178
Brian R. Bondy Avatar answered Jan 31 '23 19:01

Brian R. Bondy