ubit
Public Member Functions | Protected Attributes | List of all members
ubit::UServerSocket Class Reference

UServerSocket. More...

#include <usocket.hpp>

Public Member Functions

 UServerSocket ()
 creates an unbound server socket (bind(port) MUST then be called).
 
 UServerSocket (int port)
 creates and binds a server socket (by calling bind(port, 0, true)).
 
virtual ~UServerSocket ()
  destructor; closes this socket.
 
virtual void onInput (UCall &)
 adds a callback that is fired when data is received on the server socket. More...
 
virtual USocketaccept ()
 listens for a connection to be made and accepts it. More...
 
bool bind (int port, int backlog=0, bool reuse_address=true)
 
virtual void close ()
  closes this socket.
 
virtual USocketcreateSocket () const
 called by accept() to create the new socket (see accept() for details).
 
bool isClosed () const
 returns the closed state of the ServerSocket
 
int getLocalPort () const
 
int getDescriptor () const
 

Protected Attributes

int listen_port
 
int listen_sock
 
struct sockaddr_in * sin
 
USourceinput
 

Detailed Description

UServerSocket.

example:


creates a ServerSocket on this port
 UServerSocket* servs = new UServerSocket(666);
newConnection() will be called each time 'servs' receives a connection request
NB: in this example, 'servs' is given as an argument to the non-member fonction
newConnection() via ucall(). Aternatively, newConnection() could be an instance 
method of an object having a UServerSocket instance, see UCall for more info.
 servs->onInput(ucall(servs, newConnection));
 void newConnection(UServerSocket* servs) {
accepts the connection and returns the corresponding socket
     USocket* s = servs->accept();
     s->onInput(ucall(s, socketInputCB));  // see USocket
     ....
 }  
 

See also: USocket.

Member Function Documentation

§ accept()

USocket * ubit::UServerSocket::accept ( )
virtual

listens for a connection to be made and accepts it.

This method blocks until a connection is made. It is typically called in a callback function: see onInput() and class UServerSocket

Note: accept() calls createSocket() to create the new socket. By default this functions returns {new USocket}. It can be redefined by UServerSocket subclasses to create appropriate socket objets.

§ onInput()

void ubit::UServerSocket::onInput ( UCall c)
virtual

adds a callback that is fired when data is received on the server socket.

accept() is typically called in such a callback


The documentation for this class was generated from the following files: