GClasses
GClasses::GTCPClient Class Reference

Detailed Description

This class is an abstraction of a TCP client socket connection.

#include <GSocket.h>

Public Member Functions

 GTCPClient ()
 
virtual ~GTCPClient ()
 
void connect (const char *addr, unsigned short port, int timeoutSecs=20)
 Connect to a server. Throws an exception if it fails to connect within the specified timout period. More...
 
void disconnect ()
 Disconnect from the server. More...
 
bool isConnected ()
 Returns true iff the socket is connected. More...
 
size_t receive (char *buf, size_t len)
 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. It also returns 0 if the server has closed the connection, so you should periodically call isConnected() to make sure the connection is still open. More...
 
void send (const char *buf, size_t len)
 Send some data. Throws an exception if the send fails for any reason (including common reasons, such as if the server has closed the connection), so it is generally a good idea to send within a try/catch block. More...
 

Protected Member Functions

virtual void onDisconnect ()
 This is called when the connection is first known to have disconnected. More...
 

Protected Attributes

SOCKET m_sock
 

Constructor & Destructor Documentation

GClasses::GTCPClient::GTCPClient ( )
virtual GClasses::GTCPClient::~GTCPClient ( )
virtual

Member Function Documentation

void GClasses::GTCPClient::connect ( const char *  addr,
unsigned short  port,
int  timeoutSecs = 20 
)

Connect to a server. Throws an exception if it fails to connect within the specified timout period.

void GClasses::GTCPClient::disconnect ( )

Disconnect from the server.

bool GClasses::GTCPClient::isConnected ( )

Returns true iff the socket is connected.

virtual void GClasses::GTCPClient::onDisconnect ( )
inlineprotectedvirtual

This is called when the connection is first known to have disconnected.

size_t GClasses::GTCPClient::receive ( char *  buf,
size_t  len 
)

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. It also returns 0 if the server has closed the connection, so you should periodically call isConnected() to make sure the connection is still open.

void GClasses::GTCPClient::send ( const char *  buf,
size_t  len 
)

Send some data. Throws an exception if the send fails for any reason (including common reasons, such as if the server has closed the connection), so it is generally a good idea to send within a try/catch block.

Member Data Documentation

SOCKET GClasses::GTCPClient::m_sock
protected