Async  1.3.1
Public Member Functions | Public Attributes | List of all members
Async::TcpServer Class Reference

A class for creating a TCP server. More...

#include <AsyncTcpServer.h>

Inheritance diagram for Async::TcpServer:

Public Member Functions

 TcpServer (const std::string &port_str, const Async::IpAddress &bind_ip=IpAddress())
 Default constuctor. More...
 
 ~TcpServer (void)
 Destructor. More...
 
int numberOfClients (void)
 Get the number of clients that is connected to the server. More...
 
TcpConnectiongetClient (unsigned int index)
 Get the client object pointer from the server. More...
 
int writeAll (const void *buf, int count)
 Write data to all connected clients. More...
 
int writeOnly (TcpConnection *con, const void *buf, int count)
 Send data only to the given client. More...
 
int writeExcept (TcpConnection *con, const void *buf, int count)
 Send data to all connected clients except the given client. More...
 

Public Attributes

sigc::signal< void, TcpConnection * > clientConnected
 A signal that is emitted when a client connect to the server. More...
 
sigc::signal< void, TcpConnection *, TcpConnection::DisconnectReasonclientDisconnected
 A signal that is emitted when a client disconnect from the server. More...
 

Detailed Description

A class for creating a TCP server.

Author
Tobias Blomberg
Date
2003-12-07

This class is used to create a TCP server that listens to a TCP-port. To use it, just create an instance and specify the TCP-port to listen to. When a client connects, a new Async::TcpConnection object is created which is used to do the actual communication. An example of how to use it is shown below.

Definition at line 126 of file AsyncTcpServer.h.

Constructor & Destructor Documentation

Async::TcpServer::TcpServer ( const std::string &  port_str,
const Async::IpAddress bind_ip = IpAddress() 
)

Default constuctor.

Parameters
port_strA port number or service name to listen to
Async::TcpServer::~TcpServer ( void  )

Destructor.

Member Function Documentation

TcpConnection* Async::TcpServer::getClient ( unsigned int  index)

Get the client object pointer from the server.

Parameters
indexThe wanted client by number 0 - numberOfClients()-1
Returns
The TcpConnection pointer to the client (zero if not found)
int Async::TcpServer::numberOfClients ( void  )

Get the number of clients that is connected to the server.

Returns
The number of connected clients
int Async::TcpServer::writeAll ( const void *  buf,
int  count 
)

Write data to all connected clients.

Parameters
bufThe data buffer
countThe number of bytes in the data buffer
Returns
The number of bytes sent
int Async::TcpServer::writeExcept ( TcpConnection con,
const void *  buf,
int  count 
)

Send data to all connected clients except the given client.

Parameters
conThe TcpConnection object not to send to
bufThe data buffer
countThe number of bytes in the data buffer
Returns
The number of bytes sent
int Async::TcpServer::writeOnly ( TcpConnection con,
const void *  buf,
int  count 
)

Send data only to the given client.

Parameters
conThe TcpConnection object to send to
bufThe data buffer
countThe number of bytes in data buffer
Returns
The number of bytes sent

Member Data Documentation

sigc::signal<void, TcpConnection *> Async::TcpServer::clientConnected

A signal that is emitted when a client connect to the server.

Parameters
conThe connected TcpConnection object

Definition at line 184 of file AsyncTcpServer.h.

sigc::signal<void, TcpConnection *,TcpConnection::DisconnectReason> Async::TcpServer::clientDisconnected

A signal that is emitted when a client disconnect from the server.

Parameters
conThe disconnected TcpConnection object

Definition at line 192 of file AsyncTcpServer.h.


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