Google

C++ Portable Types Library (PTypes) Version 1.7


Top: Networking: ipstmserver

#include <pinet.h>

ipstmserver::ipstmserver();

void ipstmserver::bind(ipaddress ip, int port);
void ipstmserver::bindall(int port);

bool ipstmserver::poll(int bindnum = -1, int timeout = 0);
bool ipstmserver::serve(ipstream& client, int bindnum = -1, int timeout = -1);

The ipstmserver class is used on the server side of a stream-oriented client-server application. It bounds itself to a specified port/address and waits until a connection request is received from a client host. For each connection request a server application performs some actions and returns to the waiting state. For better performance your daemon may start a new thread for each client connection.

ipstmserver can generate exceptions of type (estream*) with a corresponding error code and a message string.

ipstmserver::ipstmserver() constructs an ipstmserver object.

void ipstmserver::bind(ipaddress ip, int port) binds the server to the specified local IP address and port number. This function can be called multiple times for different local addresses and port numbers.

void ipstmserver::bindall(int port) binds the server to all local IP address on the specified port number. Can be called multiple times for different port numbers.

bool ipstmserver::poll(int bindnum = -1, int timeout = 0) polls the listening sockets for connection requests. Bindnum specifies the socket number to test. The numbering of bound sockets corresponds to the order in which functions bind() or bindall() were called, starting from 0. If bindnum is -1 poll() will test all sockets. The second parameter timeout specifies the amount of time in milliseconds to wait for a connection request. If timeout is 0 poll() will return immediately; if it's -1 poll() will wait infinitely. This function returns true if there is a new connection request waiting for processing.

bool ipstmserver::serve(ipstream& client, int bindnum = -1, int timeout = -1) polls the specified bound sockets for connection requests. If there is a connection request, serve() opens and prepares the supplied ipstream object for communicating with the client, i.e. client will be active upon return from serve() and will contain the peer IP address and the port number. The meanings of bindnum and timeout are the same as for poll() except that the default value for timeout in this case is -1, i.e. wait infinitely. This function returns true if there is a new connection request and client is active, or false if the call has timed out.

See also: ipstream, Utilities, Examples


PTypes home