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

ssobjects::ClientConnector Class Reference

Blocking client class that a client app uses to connect to a server. More...

#include <clientconnector.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...

PacketBufferrecvPacket ()
 Receives a packet. More...

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

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

void operator>> (PacketBuffer &)
 Receives a packet. More...

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

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

CONSTCHARgetServer ()
 Returns the server host name you assigned this client object. More...

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

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

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

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

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

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


Protected Methods

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


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...

BufferedSocketm_pSocket
 Socket connected to the server. More...


Detailed Description

Blocking client class that a client app uses to connect to a server.

Use this class when you want to connect to a server that uses ssobjects. ClientConnector provides methods and operators for sending a receiving packets to/from the server you are connected to.


Constructor & Destructor Documentation

ClientConnector::ClientConnector  
 

Default constructor. [Windows only] If ClientConnector hasn't yet called WSAStartup, it will be called now.

Exceptions:
ClientConnectorException  [Windows only] If WSAStartup failed.
Todo:
Instead of using a flag, a reference count should be used so if there are multiple instances of ClientConnector, the windows socket layer won't be closed down.

ClientConnector::ClientConnector const char *    pszHost,
word    wPort
 

Constructs and connects to host.

Constructs a ClientConnector object and connects to the host. [Win32] If the WSAStartup hasn't been called, it will be called at this point. Upon destruction, WSACleanup will be called.

Parameters:
pszHost  [in] Describe what host to connect to.
wPort  [in] Describe what port to connect to on pszHost
Note:
[Win32] Currently, if you create and use more then one at the same time, ClientConnector will call WSACleanup when the first ClientConnector goes out of scape. If you try socket operations with the section, it will fail.
Exceptions:
ClientConnectorException  If Windows WSAStartup failed (Windows only).
SocketInstanceException  If there is a socket or connect error.

ClientConnector::~ClientConnector  
 

Destroys and closes any connections.

Closes connection.

[Win32] Also calls WSACleanup.

Note:
[Win32] Currently, if you create and use more then one at the same time, ClientConnector will call WSACleanup when the first ClientConnector goes out of scape. If you try socket operations with the section, it will fail.


Member Function Documentation

void ClientConnector::cleanup   [protected]
 

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

Closes the socket and deletes the memory accociated with the socket. It will not throw any exceptions on error. Use this when you are in a catch block, and need to close the connection.

void ClientConnector::close  
 

Closes the connection to the server.

Closes the connection and deletes the memory accociated with the socket.

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

void ClientConnector::connect const char *    szHost,
const unsigned    wPort
 

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

Parameters:
szHost  [in] Describe what host to connect to.
wPort  [in] Describe what port to connect to on szHost.
Stores the information you pass in, and then tries to connect to that server.
Exceptions:
See  ClientConnector::connect for details.

void ClientConnector::connect  
 

Connects to the server.

Attempts to connect to the server.

[Win32] If ClientConnector hasn't yet called WSAStartup, it will be called now.

Exceptions:
SocketInstanceException  If unable to make a connection or socket creation failed.
ClientConnectorException  If the socket is already connected.

word ssobjects::ClientConnector::getPort   [inline]
 

Returns the port you assigned this client object.

CONSTCHAR* ssobjects::ClientConnector::getServer   [inline]
 

Returns the server host name you assigned this client object.

BufferedSocket * ClientConnector::getSocket  
 

Returns:
The socket this client object is connected to.
Exceptions:
ClientConnectorException  If the socket isn't connected to anything.

void ssobjects::ClientConnector::handleException GeneralException   e
 

Not currently used.

bool ssobjects::ClientConnector::isConnected   [inline]
 

Returns if this client is connected or not.

void ClientConnector::operator<< PacketBuffer   ppacket
 

Sends the packet.

Send the data pointed to by ppacket.

Exceptions:
ClientConnectorException  If socket is not connected.
SocketInstanceException  If there was a socket error during send operation.

void ClientConnector::operator<< PacketBuffer   packet
 

Sends the packet.

Send the data referenced by packet.

Exceptions:
ClientConnectorException  If socket is not connected.
SocketInstanceException  If there was a socket error during send operation.

void ClientConnector::operator>> PacketBuffer   packet
 

Receives a packet.

Reads a full packet from the socket.

Exceptions:
ClientConnectorException  If the socket is not connected.
SocketInstanceException  If there is a read error or socket gets closed.
Note:
This is not as efficient as using ClientConnector::recvPacket, as ssobjects creates a new packet, then copies this to the reference you passed in. It does however let you make cleaner C++ code.

void ClientConnector::reconnect  
 

Tries to reconnect to the server.

Closes down any existing connection, and tries to connect to the server by calling connect() method.

Exceptions:
See  ClientConnector::connect for details.

PacketBuffer * ClientConnector::recvPacket  
 

Receives a packet.

Reads a full packet from the socket.

Returns:
A PacketBuffer pointer that points to the data that was just read. This packet was created when the data was read in. You are responsible for destrying the memory once you are finished with the packet.
Exceptions:
ClientConnectorException  If the socket is not connected.
SocketInstanceException  If there is a read error or socket gets closed.
Note:
This is more effiecent then using the ">>" operator.

void ClientConnector::sendPacket PacketBuffer   packet
 

Sends the packet.

Exceptions:
ClientConnectorException  If socket is not connected.
SocketInstance  If there is a socket error during the send operation.

void ClientConnector::sendPacket PacketBuffer   pPkt
 

Sends the packet.

Exceptions:
ClientConnectorException  If socket is not connected.
SocketInstance  If there is a socket error during the send operation.


Member Data Documentation

BufferedSocket* ssobjects::ClientConnector::m_pSocket [protected]
 

Socket connected to the server.

CStr ssobjects::ClientConnector::m_strHost [protected]
 

Host name of the server you wish to connect to.

unsigned16 ssobjects::ClientConnector::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