ubit::UServerSocket Class Reference

UServerSocket. More...

#include <usocket.hpp>

List of all members.

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.
virtual USocketaccept ()
 listens for a connection to be made and accepts it.
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
sockaddr_in * sin
UInputinput


Detailed Description

UServerSocket.

example:


creates a ServerSocket on this port
 UServerSocket* se = new UServerSocket(666);

foo() will be called each time the servsoket receives a connection
request. Note that the servsocket is given as an argument to foo()
 se->onInput(ucall(se, foo));

 void foo(UServerSocket* se) {
accepts the connection an returns the corresponding socket
     USocket* so = se->accept();
     ....
 }  
 
See also: USocket.


Member Function Documentation

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.

void ubit::UServerSocket::onInput ( UCall  )  [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:
Generated on Mon Jan 29 00:20:55 2007 for Ubit by  doxygen 1.4.7