captainc Messages: 278 Registered: December 2006 Location: New Jersey, USA
Experienced Member
Usually when listening for incoming socket connections, you have a socket server that listens and hands off connections to other individual sockets (threads).
U++ has ServerSocket for this.
This is partial code I used in an application to receive data:
if( !ServerSocket(_accept_socket, _port, false, 1000, false) ){
// throw exception...
}
//do this in a loop:
if( _accept_socket.IsOpen() ){ // server read from data socket
dword ip_addr;
if( (!_accept_socket.IsError()) && _accept_socket.Accept(_data_socket, &ip_addr) ){
_content_buf.Clear();
while( _data_socket.IsOpen() && !_data_socket.IsEof() && !_data_socket.IsError())
{_content_buf.Cat(_data_socket.Read());}
}
// do something with content buf...
}
So you can see the _accept_socket gets the connection and hands it off to _data_socket with the Accept() method. Then _data_socket has the connection.
Servers use this method with "Thread Pools" of socket connections to allow for a certain number of sockets to exist (usually 1 per thread).
Also do a search online for "BSD Sockets" or "Berkeley Sockets" to get a better understanding of the underlying technologies.