Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

ssobjects::AsyncClientConnector Class Reference

Non-blocking client class that a client app uses to connect to a server. More...

#include <asyncclientconnector.h>

List of all members.

Public Methods

void handleException (GeneralException &e)
 Not currently used. More...

void sendPacket (PacketBuffer *pPkt)
 Sends the packet. More...

void sendPacket (PacketBuffer &pPkt)
 Sends the packet. More...

void operator<< (PacketBuffer &)
 Sends the packet. More...

void operator<< (PacketBuffer *)
 Sends the packet. More...

PacketMessagegetMsg ()
 Retrieves the next message from the message queue. More...

 AsyncClientConnector (const char *pszHost, word wPort)
 Constructs and connects to host. More...

 ~AsyncClientConnector ()
 Destroys and closes any connections. More...

const char * getServer ()
 Returns the server host name you assigned this client object. More...

const word getPort ()
 Returns the port you assigned this client object. More...

bool isConnected ()
 Returns if this client is connected or not. More...

ServerSocketgetSocket ()
 Returns the ServerSocket of this client object. More...

void reconnect ()
 Tries to reconnect to the server. More...

void connect (const char *pszHost, const unsigned16 wPort)
 Stores server info passed in, and attempts to connect to the server. More...

void connect ()
 Connects to the server. More...

void close ()
 Closes the connection to the server. More...

bool idle ()
 You call this so AsyncClientConnector can check for incoming data. More...


Protected Methods

void cleanup ()
 Closes the connection without throwing any exeptions on errors during socket closer. Deletes the socket. More...

void setNonBlocking (SOCKET sockfd)

Protected Attributes

unsigned16 m_wPort
 Port number of the server you wish to connect to. More...

CStr m_strHost
 Host name of the server you wish to connect to. More...

ServerSocketm_pSocket
 Socket connected to the server. More...

PacketMessageQue m_que
 Message que that contains any messages that have been parsed from read socket data. More...


Detailed Description

Non-blocking client class that a client app uses to connect to a server.

This is an asynchronis client class used so you can poll for incoming packets. If there are no packets available, your program will not block. If there is incoming data, it will be read and parsed into packets and posted to the message queue if possible.

You would use this class if you didn't want to use threads. Note however, since this class uses the PacketMessageQue class, you must still compile using threading options.


Constructor & Destructor Documentation

AsyncClientConnector::AsyncClientConnector const char *    pszHost,
word    wPort
 

Constructs and connects to host.

Constructs a AsyncClientConnector object and connects to host pointed to by pszHost on port pointed to by wPort.

Exceptions:
AsyncClientConnectorException  [Windows only] If Windows WSAStartup failed

AsyncClientConnector::~AsyncClientConnector  
 

Destroys and closes any connections.


Member Function Documentation

void AsyncClientConnector::cleanup   [protected]
 

Closes the connection without throwing any exeptions on errors during socket closer. Deletes the socket.

void AsyncClientConnector::close  
 

Closes the connection to the server.

Exceptions:
AsyncClientConnectorException  If socket was not connected.
SocketInstanceException  If there was a socket error during close operation.

void AsyncClientConnector::connect  
 

Connects to the server.

Attempts to connect to the server. Once connected, the socket is put into non-blocking mode.

Exceptions:
SocketInstanceException  If unable to make a connection or socket creation failed.

void AsyncClientConnector::connect const char *    pszHost,
const unsigned16    wPort
 

Stores server info passed in, and attempts to connect to the server.

Stores the information you pass in, and then tries to connect to that server.

Exceptions:
See  AsyncClientConnector::connect for details.

PacketMessage * AsyncClientConnector::getMsg  
 

Retrieves the next message from the message queue.

Gets the next message, and removes it from the message queue.

Returns:
NULL if there are no messages. A pointer to the next message otherwise.

const word ssobjects::AsyncClientConnector::getPort   [inline]
 

Returns the port you assigned this client object.

const char* ssobjects::AsyncClientConnector::getServer   [inline]
 

Returns the server host name you assigned this client object.

ServerSocket * AsyncClientConnector::getSocket  
 

Returns the ServerSocket of this client object.

void ssobjects::AsyncClientConnector::handleException GeneralException   e
 

Not currently used.

bool AsyncClientConnector::idle  
 

You call this so AsyncClientConnector can check for incoming data.

You call idle as often as you are able to. When idle is called, it will check for incoming data. If there is data on the connected socket, it will be read, and parsed into packets. If the connection is closed gracefully on the other end, PacketBuffer::pcClosed is posted to the message que. If the connection is not closed gracefully, and exeption is generated.

Exceptions:
AsyncClientConnectorException  If there was any read or select errors.
Returns:
true if there was packets parsed. false otherwise.

bool ssobjects::AsyncClientConnector::isConnected   [inline]
 

Returns if this client is connected or not.

void AsyncClientConnector::operator<< PacketBuffer   ppacket
 

Sends the packet.

Exceptions:
AsyncClientConnectorException  If the socket is not connected.

void AsyncClientConnector::operator<< PacketBuffer   packet
 

Sends the packet.

Exceptions:
AsyncClientConnectorException  If the socket is not connected.

void AsyncClientConnector::reconnect  
 

Tries to reconnect to the server.

Closes down any existing connection, and tries to connect to the server.

Exceptions:
See  AsyncClientConnector::connect for details.

void AsyncClientConnector::sendPacket PacketBuffer   packet
 

Sends the packet.

Attempts to send the packet referenced by packet.

Exceptions:
AsyncClientConnectorException  If the socket is not connected.

void AsyncClientConnector::sendPacket PacketBuffer   pPkt
 

Sends the packet.

Attempts to send the packet pointed to by pPkt.

Asserts if pPkt is NULL.

Exceptions:
AsyncClientConnectorException  If the socket is not connected.

void AsyncClientConnector::setNonBlocking SOCKET    sockfd [protected]
 

Sets the socket to non-blocking mode.

Exceptions:
AsyncClientConnectorException  If unable to set socket to non-blocking mode.
Note:
[Windows only] When compiled for windows, this is an empty function. Socket is not put into non-blocking mode.


Member Data Documentation

ServerSocket* ssobjects::AsyncClientConnector::m_pSocket [protected]
 

Socket connected to the server.

PacketMessageQue ssobjects::AsyncClientConnector::m_que [protected]
 

Message que that contains any messages that have been parsed from read socket data.

CStr ssobjects::AsyncClientConnector::m_strHost [protected]
 

Host name of the server you wish to connect to.

unsigned16 ssobjects::AsyncClientConnector::m_wPort [protected]
 

Port number of the server you wish to connect to.


The documentation for this class was generated from the following files:
Generated on Thu Nov 8 12:39:27 2001 for SimpleServerObjects by doxygen1.2.11 written by Dimitri van Heesch, © 1997-2001