GClasses
|
This class is an abstraction of a TCP server, which maintains a set of socket connections. More...
#include <GSocket.h>
Public Member Functions | |
GTCPServer (unsigned short port) | |
virtual | ~GTCPServer () |
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. | |
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. | |
void | disconnect (GTCPConnection *pConn) |
Disconnect from the specified client. | |
in_addr | ipAddr (GTCPConnection *pConn) |
Returns the client's IP address for the specified connection. | |
Static Public Member Functions | |
static void | hostName (char *buf, size_t len) |
Obtains the name of this host. | |
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.) | |
virtual void | onDisconnect (GTCPConnection *pConn) |
This is called when a connection is first known to have disconnected. | |
virtual void | onReceiveBadData (const char *message) |
This is called when a client sends some bad data. | |
void | checkForNewConnections () |
Accept any new incoming connections. | |
Protected Attributes | |
SOCKET | m_sock |
std::set< GTCPConnection * > | m_socks |
This class is an abstraction of a TCP server, which maintains a set of socket connections.
GClasses::GTCPServer::GTCPServer | ( | unsigned short | port | ) |
virtual GClasses::GTCPServer::~GTCPServer | ( | ) | [virtual] |
void GClasses::GTCPServer::checkForNewConnections | ( | ) | [protected] |
Accept any new incoming connections.
void GClasses::GTCPServer::disconnect | ( | GTCPConnection * | pConn | ) |
Disconnect from the specified client.
static void GClasses::GTCPServer::hostName | ( | char * | buf, |
size_t | len | ||
) | [static] |
Obtains the name of this host.
in_addr GClasses::GTCPServer::ipAddr | ( | GTCPConnection * | pConn | ) |
Returns the client's IP address for the specified connection.
virtual GTCPConnection* GClasses::GTCPServer::makeConnection | ( | SOCKET | s | ) | [inline, protected, virtual] |
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.)
Reimplemented in GClasses::GPackageServer.
virtual void GClasses::GTCPServer::onDisconnect | ( | GTCPConnection * | pConn | ) | [inline, protected, virtual] |
This is called when a connection is first known to have disconnected.
virtual void GClasses::GTCPServer::onReceiveBadData | ( | const char * | message | ) | [inline, protected, virtual] |
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.
Reimplemented in GClasses::GPackageServer.
SOCKET GClasses::GTCPServer::m_sock [protected] |
std::set<GTCPConnection*> GClasses::GTCPServer::m_socks [protected] |