Click to See Complete Forum and Search --> : Socket Type Selection


vinay_619@rediffmail.com
October 4th, 2005, 02:25 AM
We have got multithreaded server and there will be maximum of 100 GUI threads running at the same time and each thread will have to handle 15 socket connections. Currently we are using CSocket and we are facing problems like thread get hangs. Socket is the part of GUI thread there is no separate thread for Socket handling. Current Design is blocking in nature. We need better and reliable alternative
Currently we have the following choices
CAsyncSocket
Socket library at http://www.alhem.net
Or some better one
And main thing is we are short of time :(
Kindly suggest us
thanks

MikeAThon
October 4th, 2005, 03:41 PM
Threads are "hanging" because each one is handling 15 sockets, and your sockets are blocking. Thus, one socket will block all 14 of the other sockets being handled by that thread.

In blocking architectures, it's typical that there is exactly one socket per thread. 15 blocking sockets per thread probably can't work.

If you truly expect to be able to handle 100 x 15 = 1500 simultaneous connections, then you should abandon message-based sockets like CAsyncSocket. At a minumum, you should be using event-based sockets, for which I am not aware of a library (MFC does not provide one). Better still, you should be looking at overlapped operations with IO completion ports.

See this thread, and the table reproduced inside of it, for a discussion of the number of connections that each different architecture might be able to support: http://www.codeguru.com/forum/showthread.php?p=1182005#post1182005 . It includes a quote from the book "Network Programming For Microsoft Windows, second edition" by Anthony Jones and Jim Ohlund.

None of this is easy, and "short of time" will not help. If you are interested in IOCP-based models, then be aware that the minimum platform is Win 2000 (i.e., IOCP will not work on Win 98).

An approachable introduction to completion ports can be found at "A simple IOCP Server/Client Class" at http://www.codeproject.com/internet/IOCP_Server_client.asp . Another good article is found in the October 2000 issue of MSDN magazine: "Windows Sockets 2.0: Write Scalable Winsock Apps Using Completion Ports" by Anthony Jones (well-known winsock expert at Microsoft) at http://msdn.microsoft.com/msdnmag/issues/1000/Winsock/

Mike