Simple++
Powerfull and lightning fast C++ Library
Public Member Functions | Static Public Member Functions | List of all members
Network::Server Class Reference

Represent a listening server who can handle multiple protocol or ip family. More...

#include <Server.h>

Public Member Functions

 Server ()
 Create a new Server. More...
 
 ~Server ()
 destructor More...
 
bool listen (unsigned short port, SockType sockType=SockType::TCP, IpFamily ipFamily=IpFamily::Undefined, int maxClients=100)
 Add a listen address to this server. More...
 
bool listen (const String &address, const String &service, SockType sockType=SockType::TCP, IpFamily ipFamily=IpFamily::Undefined, int maxClients=100)
 Add a listen address to this server. More...
 
bool listen (const String &address, unsigned int port, SockType sockType=SockType::TCP, IpFamily ipFamily=IpFamily::Undefined, int maxClients=100)
 Add a listen address to this server. More...
 
bool listen (const Address &addrInfo, int maxClients=100)
 Add a listen address to this server. More...
 
Vector< Connection * >::Size getNumConnections () const
 get the number of connection this server has More...
 
bool accept (Connection *clientSocket)
 Accept a new Client from one of the connections (only when listening on TCP) More...
 
bool close ()
 close all the connections More...
 
int receive (char *buffer, int maxSize, Address *addressFrom)
 Wait to receive a message from one of the connections. More...
 

Static Public Member Functions

static size_t getMaximumNbConnections ()
 get the maximum number of connections a server can have. More...
 

Detailed Description

Represent a listening server who can handle multiple protocol or ip family.

Constructor & Destructor Documentation

Network::Server::Server ( )

Create a new Server.

Network::Server::~Server ( )

destructor

Member Function Documentation

bool Network::Server::accept ( Connection clientSocket)

Accept a new Client from one of the connections (only when listening on TCP)

Parameters
clientSocketObject to be filled with the incoming client (the object has to be allocated)
Returns
true if success else false
bool Network::Server::close ( )

close all the connections

Returns
true if success else false
size_t Network::Server::getMaximumNbConnections ( )
static

get the maximum number of connections a server can have.

Returns
maximum number of connections of a server.
Vector< Connection * >::Size Network::Server::getNumConnections ( ) const

get the number of connection this server has

Returns
Actual number of connections of this server.
bool Network::Server::listen ( unsigned short  port,
SockType  sockType = SockType::TCP,
IpFamily  ipFamily = IpFamily::Undefined,
int  maxClients = 100 
)

Add a listen address to this server.

Parameters
portPort onto listen.
sockTypeTCP or UDP
ipFamilyIPv4, IPV6 or Undefined for both
maxClientsMaximum number of clients accepted (Only for TCP)
Returns
true if success else false
bool Network::Server::listen ( const String address,
const String service,
SockType  sockType = SockType::TCP,
IpFamily  ipFamily = IpFamily::Undefined,
int  maxClients = 100 
)

Add a listen address to this server.

Parameters
addressAddress as String (IP or domain name)
serviceto look for.
sockTypeTCP or UDP
ipFamilyIPv4, IPV6 or Undefined for both
maxClientsMaximum number of clients accepted (Only for TCP)
Returns
true if success else false
bool Network::Server::listen ( const String address,
unsigned int  port,
SockType  sockType = SockType::TCP,
IpFamily  ipFamily = IpFamily::Undefined,
int  maxClients = 100 
)

Add a listen address to this server.

Parameters
addressAddress as String (IP or domain name)
portPort onto listen.
sockTypeTCP or UDP
ipFamilyIPv4, IPV6 or Undefined for both
maxClientsMaximum number of clients accepted (Only for TCP)
Returns
true if success else false
bool Network::Server::listen ( const Address addrInfo,
int  maxClients = 100 
)

Add a listen address to this server.

Parameters
addrInfoAddress to be binded
maxClientsMaximum number of clients accepted (Only for TCP)
Returns
true if success else false
int Network::Server::receive ( char *  buffer,
int  maxSize,
Address addressFrom 
)

Wait to receive a message from one of the connections.

Parameters
bufferto be filled with the new message.
maxSizeMaximum size of the message in bytes
addressFromAddress to be filled with the incoming sender (the object has to be already allocated)
Returns
number of bytes read

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