Serial-TCP/IPbridge  1.0
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
TCPIPServer Class Reference

TCPIP server that accepts client connections. More...

#include <tcpip_server.h>

Classes

class  TCPIPServerError
 This exception is thrown in case of some server error. More...
 

Public Member Functions

 TCPIPServer (const TCPIPConfig &config)
 Constructor. More...
 
 ~TCPIPServer ()
 Destructor. More...
 
std::auto_ptr< TCPIPConnectiontryAcceptConnection ()
 Tries to accept a TCP/IP connection from a client. More...
 
void stopListening ()
 Stops listening (accepting new connections). More...
 

Private Types

typedef std::vector< int > Sockets
 List of sockets. More...
 
typedef std::vector< std::string > IPAddresses
 List of IPv4 addresses. More...
 

Private Member Functions

 TCPIPServer (const TCPIPServer &)
 
TCPIPServeroperator= (const TCPIPServer &)
 
IPAddresses getAddressesToListenOn (const TCPIPConfig::Interfaces &interfaces)
 Returns a list of IPv4 address on which the server should listen on. More...
 
IPAddresses getInterfaceAddresses (const std::string &interface)
 Returns all IPv4 address associated with the selected interface. More...
 

Private Attributes

const TCPIPConfig _config
 TCP/IP configuration. More...
 
Sockets _sockets
 List of sockets on which the server listens. More...
 

Static Private Attributes

static const int MAX_CONNECTION_COUNT
 Maximal incoming connection count. More...
 

Detailed Description

TCPIP server that accepts client connections.

This class provides a server which listens on the selected interface and port and accepts client connections.

It provides reference semantics (objects copying and comparison is NOT allowed).

Member Typedef Documentation

typedef std::vector<std::string> TCPIPServer::IPAddresses
private

List of IPv4 addresses.

typedef std::vector<int> TCPIPServer::Sockets
private

List of sockets.

Constructor & Destructor Documentation

TCPIPServer::TCPIPServer ( const TCPIPConfig config)
explicit

Constructor.

Parameters
configTCP/IP configuration.

Creates and initializes a TCPIPServer object and starts listening (accepting new connections). If there is some error, TCPIPServerError will be thrown.

Server "tryX" operations will be blocking (by default). You can change this by calling setBlocking(false).

TCPIPServer::~TCPIPServer ( )

Destructor.

TCPIPServer::TCPIPServer ( const TCPIPServer )
private

Member Function Documentation

IPAddresses TCPIPServer::getAddressesToListenOn ( const TCPIPConfig::Interfaces interfaces)
private

Returns a list of IPv4 address on which the server should listen on.

Parameters
interfacesThe list of network interfaces and/or IPv4 addresses (or TCPIPConfig::ANY_INTERFACE).
Returns
All IPv4 addresses on which the server should listen on.

If one value in the interfaces list is TCPIPConfig::ANY_INTERFACE, then the server should listen on all available interfaces and a list containing one value (TCPIPConfig::ANY_INTERFACE) will be returned.

If there is an error (e.g. IP addresses for some interface cannot be obtained), TCPIPServerError exception will be thrown.

IPAddresses TCPIPServer::getInterfaceAddresses ( const std::string &  interface)
private

Returns all IPv4 address associated with the selected interface.

Parameters
interfaceThe network interface.
Returns
All IPv4 address associated with interface.

If there is an error (e.g. non-existing interface), TCPIPServerError exception will be thrown.

Todo:
Currently only one IP will be returned. I haven't found any way how to obtain all IP addresses of an interface yet.
TCPIPServer& TCPIPServer::operator= ( const TCPIPServer )
private
void TCPIPServer::stopListening ( )

Stops listening (accepting new connections).

std::auto_ptr<TCPIPConnection> TCPIPServer::tryAcceptConnection ( )

Tries to accept a TCP/IP connection from a client.

Returns
Accepted connection or auto_ptr<TCPIPConnection>(0), if there was no connection to be accepted.

The behaviour of this operation is nonblocking (i.e., when there is no connection to be accepted, it returns immediately).

In case of a connection error, TCPIPConnection::TCPIPConnectionError exception is thrown.

Member Data Documentation

const TCPIPConfig TCPIPServer::_config
private

TCP/IP configuration.

Sockets TCPIPServer::_sockets
private

List of sockets on which the server listens.

const int TCPIPServer::MAX_CONNECTION_COUNT
staticprivate

Maximal incoming connection count.


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