Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » Socket in a sock
Re: Socket in a sock [message #17528 is a reply to message #17511] Tue, 19 August 2008 14:30 Go to previous messageGo to previous message
captainc is currently offline  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.

 
Read Message icon5.gif
Read Message
Read Message icon3.gif
Read Message
Previous Topic: sending post message
Next Topic: Socket documentation
Goto Forum:
  


Current Time: Sun Apr 28 06:34:32 CEST 2024

Total time taken to generate the page: 0.04348 seconds