Class Hierarchy   Class Index   Method Index  

CHMhl7ServerSocket Class Reference

#include <CHMhl7ServerSocket.h>


Detailed Description

Deprecated server class for asynchronous TCP/IP communication.

This should not be used for new applications.

The CHMhl7ServerSocket represents a listener on a port that can receive remote connections. It also supports sending and receiving messages across these connections. The messages are automatically wrapped and unwrapped using the LLP protocol. To implement a CHMhl7ServerSocket you must create a new class that inheirits from it. This way you can override the virtual methods to handle the network events.

Deprecated:


Public Member Functions

 CHMhl7ServerSocket ()
 Constructor The default constructor creates a server object that's ready to listen.
virtual ~CHMhl7ServerSocket ()
 Destructor.
void listen (short Port)
 Makes server listen on a specified port Calling listen makes this socket start listening on the port specified.
void stopListening ()
 Stops the server from listening Calling this method stops the socket from listening on the port specified in the call to listen().
void sendMessage (int ClientId, const char *Message)
 Send a message.
CHMuint32 getIpAddress (int ClientId)
 Get the raw IP address.
const char * getIpAddressString (int ClientId)
 Get the IP address as a string.
const char * getHostName (int ClientId)
 Gets the host name.
void closeConnection (int ClientId)
 Close a connection.
void closeAllConnections ()
 Close all connections.
virtual CHMhl7ClientSocketonNewConnection (int ClientId)
 Called when there is a new connection This method is called when a new connection has been accepted.
virtual void onError (int ErrorId, const char *ErrorMessage)
 called when an error occurs This method is called when an error occurs with the server socket such as not being able to listen on a port.

Friends

class CHMhl7ClientSocket


Constructor & Destructor Documentation

CHMhl7ServerSocket::CHMhl7ServerSocket  ) 
 

Constructor The default constructor creates a server object that's ready to listen.

Call the listen() method to start listening.

virtual CHMhl7ServerSocket::~CHMhl7ServerSocket  )  [virtual]
 

Destructor.


Member Function Documentation

void CHMhl7ServerSocket::closeAllConnections  ) 
 

Close all connections.

Closes all the connections that this server socket has accepted.

void CHMhl7ServerSocket::closeConnection int  ClientId  ) 
 

Close a connection.

Closes the connection specified by ClientId. If the connection has already been closed this function does nothing.

Parameters:
ClientId The id of the connection you'd like to close. The ClientId must be a valid id received from CHMhl7ClientSocket or onNewConnection().

const char* CHMhl7ServerSocket::getHostName int  ClientId  ) 
 

Gets the host name.

This function does a lookup for the host name of the connection's IP address. If no host name is found then it returns the IP address of the remote host as a string.

Parameters:
ClientId The id of the connection you'd like the host name of. The ClientId must be a valid id received from CHMhl7ClientSocket or onNewConnection().
Returns:
The host name of the remote host.

CHMuint32 CHMhl7ServerSocket::getIpAddress int  ClientId  ) 
 

Get the raw IP address.

Parameters:
ClientId The id of the connection you'd like the IP of. The ClientId must be a valid id received from CHMhl7ClientSocket or onNewConnection().
Returns:
The 32 bit integer IP address of the connection specified by ClientId.

const char* CHMhl7ServerSocket::getIpAddressString int  ClientId  ) 
 

Get the IP address as a string.

Parameters:
ClientId The id of the connection you'd like the IP of. The ClientId must be a valid id received from CHMhl7ClientSocket or onNewConnection().
Returns:
The IP address of the connection specified by ClientId as a string in the form "127.0.0.1".

void CHMhl7ServerSocket::listen short  Port  ) 
 

Makes server listen on a specified port Calling listen makes this socket start listening on the port specified.

After this call is made, and there is no error, the socket is ready to receive incoming connecctions. When an incoming connnection is accepted the onNewConnection() event is called. If there is an error trying to listen the onError() event is called. Override these virtual methods on a base class to handle these events.

Parameters:
Port The port number to listen on.

virtual void CHMhl7ServerSocket::onError int  ErrorId,
const char *  ErrorMessage
[inline, virtual]
 

called when an error occurs This method is called when an error occurs with the server socket such as not being able to listen on a port.

Errors that occur on a connection are not handled here but with the onTransportError() event. You can override this method on a base class to return your own derived implementation of CHMhl7ClientSocket.

Parameters:
ErrorId The error code. This is a number that identifies the error type.
ErrorMessage A null terminated string with the error message.

virtual CHMhl7ClientSocket& CHMhl7ServerSocket::onNewConnection int  ClientId  )  [virtual]
 

Called when there is a new connection This method is called when a new connection has been accepted.

The default behavior is to create a CHMhl7ClientSocket. You can override this method on a base class to return your own derived implementation of CHMhl7ClientSocket.

Parameters:
ClientId The id of the new connection. You can use this id to create a new CHMhl7ClientSocket to return.
Returns:
A new CHMhl7ClientSocket to handle the new connection. If you override this method you can return you own derived version of CHMhl7ClientSocket to handle its events properly.

void CHMhl7ServerSocket::sendMessage int  ClientId,
const char *  Message
 

Send a message.

Sends a message on the connection specified by ClientId. This call automatically wraps the message with the LLP header and footer.

Parameters:
ClientId The id of the client to send a message to. The ClientId must be a valid id received from CHMhl7ClientSocket or onNewConnection().
Message A null terminated string representing the message that should be sent.

void CHMhl7ServerSocket::stopListening  ) 
 

Stops the server from listening Calling this method stops the socket from listening on the port specified in the call to listen().

Any incoming connection requests made after this method is called will fail.


The documentation for this class was generated from the following file: