GClasses
|
This class is an abstraction of a TCP server, which maintains a set of socket connections.
#include <GSocket.h>
Public Member Functions | |
GTCPServer (unsigned short port) | |
virtual | ~GTCPServer () |
void | checkForNewConnections () |
Accept any new incoming connections. More... | |
std::set< GTCPConnection * > & | connections () |
Returns a reference to the current set of connections. More... | |
void | disconnect (GTCPConnection *pConn) |
Disconnect from the specified client. More... | |
size_t | receive (char *buf, size_t len, GTCPConnection **pOutConn) |
This method receives any data that is ready to be received. It returns the number of bytes received. It immediately returns 0 if nothing is ready to be recevied. The value at pOutConn will be set to indicate which client it received the data from. More... | |
void | send (const char *buf, size_t len, GTCPConnection *pConn) |
Send some data to the specified client. Throws an exception if the send fails for any reason (including common reasons, such as if the client has closed the connection), so it is generally a good idea to send within a try/catch block. More... | |
Static Public Member Functions | |
static void | hostName (char *buf, size_t len) |
Obtains the name of this host. More... | |
Protected Member Functions | |
virtual GTCPConnection * | makeConnection (SOCKET s) |
This is called just before a new connection is accepted. It returns a pointer to a new GTCPConnection object to associate with this connection. (The connection, however, isn't yet fully established, so it might cause an error if you send something to the client in an overload of this method.) If you want to associate some data with each connection, you can overload this method to create a custom object. More... | |
virtual void | onDisconnect (GTCPConnection *pConn) |
This is called when a connection is first known to have disconnected. More... | |
virtual void | onReceiveBadData (const char *message) |
This is called when a client sends some bad data. More... | |
Protected Attributes | |
SOCKET | m_sock |
std::set< GTCPConnection * > | m_socks |
GClasses::GTCPServer::GTCPServer | ( | unsigned short | port | ) |
|
virtual |
void GClasses::GTCPServer::checkForNewConnections | ( | ) |
Accept any new incoming connections.
|
inline |
Returns a reference to the current set of connections.
void GClasses::GTCPServer::disconnect | ( | GTCPConnection * | pConn | ) |
Disconnect from the specified client.
|
static |
Obtains the name of this host.
|
inlineprotectedvirtual |
This is called just before a new connection is accepted. It returns a pointer to a new GTCPConnection object to associate with this connection. (The connection, however, isn't yet fully established, so it might cause an error if you send something to the client in an overload of this method.) If you want to associate some data with each connection, you can overload this method to create a custom object.
|
inlineprotectedvirtual |
This is called when a connection is first known to have disconnected.
|
inlineprotectedvirtual |
This is called when a client sends some bad data.
size_t GClasses::GTCPServer::receive | ( | char * | buf, |
size_t | len, | ||
GTCPConnection ** | pOutConn | ||
) |
This method receives any data that is ready to be received. It returns the number of bytes received. It immediately returns 0 if nothing is ready to be recevied. The value at pOutConn will be set to indicate which client it received the data from.
void GClasses::GTCPServer::send | ( | const char * | buf, |
size_t | len, | ||
GTCPConnection * | pConn | ||
) |
Send some data to the specified client. Throws an exception if the send fails for any reason (including common reasons, such as if the client has closed the connection), so it is generally a good idea to send within a try/catch block.
|
protected |
|
protected |