Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CP_ServerSocket Class Reference

Class to allow incoming socket connections.

Inheritance diagram for CP_ServerSocket:

CP_Socket List of all members.

Getters

UInt32 GetAddress () const
CP_NetworkAddress GetNetworkAddress () const
UInt32 GetPeerAddress () const
CP_NetworkAddress GetPeerNetworkAddress () const
UInt16 GetPort () const
UInt16 GetPeerPort () const
CP_String GetHostName ()
static UInt32 GetHostByName (const CP_String &inHostName)
static CP_NetworkAddress GetHostAddressByName (const CP_String &inHostName)

Public Member Functions

Constructor / Destructor
 CP_ServerSocket ()
 Constructor.
 CP_ServerSocket (UInt32 inAddress, UInt16 inPort)
 CP_ServerSocket (const CP_NetworkAddress &inAddress, UInt16 inPort)
virtual ~CP_ServerSocket () throw ()
 Destructor.
Listing
void BeginListening (SInt16 queSize=SOMAXCONN)
void BeginListening (UInt32 inAddress, UInt16 inPort, SInt16 queSize=SOMAXCONN)
void BeginListening (const CP_NetworkAddress &inAddress, UInt16 inPort, SInt16 queSize=SOMAXCONN)
CP_SocketAccept ()
Connection
void Connect (UInt32 inTimeoutInSeconds=0)
void Connect (UInt32 inAddress, UInt16 inPort, UInt32 inTimeoutInSeconds=0)
void Connect (const char *inAddress, UInt16 inPort, UInt32 inTimeoutInSeconds=0)
void Connect (const CP_NetworkAddress &inAddress, UInt16 inPort, UInt32 inTimeoutInSeconds=0)
Data Transfer
void Send (const CP_String &inMessage)
void Send (const void *inData, UInt32 inDataLength)
SInt32 Receive (void *inOutBuffer, UInt32 inOutBufferLength)
UInt32 Available () const
bool HasBytesAvailable () const
Misc
UInt32 GetHostID ()
Terminate
void Close ()
void CloseInput ()
void CloseOutput ()
Testers
bool IsConnected (char rdwr=-1) const
bool IsConnectionClosed (UInt32 inTimeoutInMicroseconds=10000) const
Connection
void Connect (UInt32 inTimeoutInSeconds=0)
void Connect (UInt32 inAddress, UInt16 inPort, UInt32 inTimeoutInSeconds=0)
void Connect (const char *inAddress, UInt16 inPort, UInt32 inTimeoutInSeconds=0)
void Connect (const CP_NetworkAddress &inAddress, UInt16 inPort, UInt32 inTimeoutInSeconds=0)
Data Transfer
void Send (const CP_String &inMessage)
void Send (const void *inData, UInt32 inDataLength)
SInt32 Receive (void *inOutBuffer, UInt32 inOutBufferLength)
UInt32 Available () const
bool HasBytesAvailable () const
Misc
UInt32 GetHostID ()
Terminate
void Close ()
void CloseInput ()
void CloseOutput ()
Testers
bool IsConnected (char rdwr=-1) const
bool IsConnectionClosed (UInt32 inTimeoutInMicroseconds=10000) const

Protected Member Functions

void Initialize (void)
void GetConnectedSocketInfo (void)
Create
virtual CP_SocketcreateSocket (int s)
Create
virtual CP_SocketcreateSocket (SOCKET s)
Create
virtual CP_SocketcreateSocket (int s)

Protected Attributes

CP_String fHostName
char fIsConnected
sockaddr_in fSocketAddress
hostentfnlp_host
int fSocketDescriptor
SOCKET fSocketDescriptor
CP_NetworkAddress fConnectedSocketAddress
UInt16 fConnectedSocketPort
CP_NetworkAddress fConnectedPeerAddress
UInt16 fConnectedPeerPort

Private Member Functions

Binding
void BindTo (UInt32 inAddress, UInt16 inPort)
void BindTo (const CP_NetworkAddress &inAddress, UInt16 inPort)

Private Attributes

bool fListening

Constructor & Destructor Documentation

CPLAT_Begin_Namespace_CPLAT CP_ServerSocket::CP_ServerSocket  ) 
 

Constructor.

Exceptions:
none 

CP_ServerSocket::CP_ServerSocket UInt32  inAddress,
UInt16  inPort
 

Constructor.

Parameters:
inAddress Address to connect to.
inPort Port to connect to.
Exceptions:
none 

CP_ServerSocket::CP_ServerSocket const CP_NetworkAddress inAddress,
UInt16  inPort
 

Constructor.

Parameters:
inAddress Address to connect to.
inPort Port to connect to.
Exceptions:
none 

CP_ServerSocket::~CP_ServerSocket  )  throw () [virtual]
 

Destructor.

Exceptions:
none 


Member Function Documentation

void CP_ServerSocket::BeginListening SInt16  queSize = SOMAXCONN  ) 
 

Begin listening for connections.

Parameters:
queSize listen que length
Exceptions:
OSErr exceptions
Returns:
void

void CP_ServerSocket::BeginListening UInt32  inAddress,
UInt16  inPort,
SInt16  queSize = SOMAXCONN
 

Begin listening for connections.

Parameters:
inAddress Will probably be 0 (meaning any local interface) but could be a specific interface (eg 127.0.0.1 for loopback only)
inPort Port on which to listen.
queSize listen que length.
Exceptions:
OSErr exceptions
Returns:
void

void CP_ServerSocket::BeginListening const CP_NetworkAddress inAddress,
UInt16  inPort,
SInt16  queSize = SOMAXCONN
 

Begin listening for connections.

Parameters:
inAddress Will probably be 0 (meaning any local interface) but could be a specific interface (eg 127.0.0.1 for loopback only)
inPort Port on which to listen.
queSize listen que length.
Exceptions:
OSErr exceptions
Returns:
void

CP_Socket * CP_ServerSocket::Accept  ) 
 

Wait for an incoming connection. Please note that this is a blocking call! You will not return from this call until a connection is received, or this socket is shutdown.

Exceptions:
OSErr exceptions
Returns:
void

Plugin point. Override if you want to create a special socket class to handle an accepted connection.

Parameters:
s Socket connection.
Exceptions:
OSErr exceptions
Returns:
CP_Socket * A CP_Socket connection.
Plugin point. Override if you want to create a special socket class to handle an accepted connection.

Parameters:
s Socket connection.
Exceptions:
OSErr exceptions
Returns:
CP_Socket * A CP_Socket connection.
Plugin point. Override if you want to create a special socket class to handle an accepted connection.

Parameters:
s Socket connection.
Exceptions:
OSErr exceptions
Returns:
CP_Socket * A CP_Socket connection.

void CP_ServerSocket::BindTo UInt32  inAddress,
UInt16  inPort
[private]
 

Bind the allocated socket to a specific address and port.

Parameters:
inAddress Will probably be 0 (meaning any local interface) but could be a specific interface (eg 127.0.0.1 for loopback only)
inPort Port on which to listen.
Exceptions:
OSErr exceptions
Returns:
void

void CP_ServerSocket::BindTo const CP_NetworkAddress inAddress,
UInt16  inPort
[private]
 

Bind the allocated socket to a specific address and port.

Parameters:
inAddress Will probably be 0 (meaning any local interface) but could be a specific interface (eg 127.0.0.1 for loopback only)
inPort Port on which to listen.
Exceptions:
OSErr exceptions
Returns:
void

virtual CP_Socket* CP_ServerSocket::createSocket int  s  )  [protected, virtual]
 

Is the socket currently accepting connections.

virtual CP_Socket* CP_ServerSocket::createSocket SOCKET  s  )  [protected, virtual]
 

virtual CP_Socket* CP_ServerSocket::createSocket int  s  )  [protected, virtual]
 

void CP_Socket::Connect UInt32  inTimeoutInSeconds = 0  )  [inherited]
 

Establish a connection with the host.

Parameters:
inTimeoutInSeconds the timeout in seconds for the connect. If timeout is 0 then now timeout will happen
Exceptions:
OSError exceptions.
Returns:
void
Todo:
check if this is OK could be in milli seconds

void CP_Socket::Connect UInt32  inAddress,
UInt16  inPort,
UInt32  inTimeoutInSeconds = 0
[inherited]
 

Establish a connection with the host.

Parameters:
inAddress The address of the host to connect to.
inPort The port to connect to.
inTimeoutInSeconds the timeout in seconds for the connect. If timeout is 0 then now timeout will happen
Exceptions:
OSError exceptions.
Returns:
void

void CP_Socket::Connect const char *  inAddress,
UInt16  inPort,
UInt32  inTimeoutInSeconds = 0
[inherited]
 

Establish a connection with the host.

Parameters:
inAddress The address of the host to connect to.
inPort The port to connect to.
inTimeoutInSeconds the timeout in seconds for the connect. If timeout is 0 then now timeout will happen
Exceptions:
OSError exceptions.
Returns:
void

void CP_Socket::Connect const CP_NetworkAddress inAddress,
UInt16  inPort,
UInt32  inTimeoutInSeconds = 0
[inherited]
 

Establish a connection with the host.

Parameters:
inAddress The address of the host to connect to.
inPort The port to connect to.
inTimeoutInSeconds the timeout in seconds for the connect. If timeout is 0 then now timeout will happen
Exceptions:
OSError exceptions.
Returns:
void

void CP_Socket::Send const CP_String inMessage  )  [inherited]
 

Sends data over the socket connection.

Parameters:
inMessage The data being sent.
Exceptions:
OSError exceptions.
Returns:
void

void CP_Socket::Send const void *  inData,
UInt32  inDataLength
[inherited]
 

Sends data over the socket connection.

Parameters:
inData Pointer to a buffer to send.
inDataLength Amount of data from the buffer to send.
Exceptions:
OSError exceptions.
Returns:
void

SInt32 CP_Socket::Receive void *  inOutBuffer,
UInt32  inOutBufferLength
[inherited]
 

Receives data from the socket connection.

Parameters:
inOutBuffer Location to return the data in.
inOutBufferLength Maximum amount of data to be read at one time.
Exceptions:
OSError exceptions.
Returns:
SInt32 The actual size of data read.

UInt32 CP_Socket::Available  )  const [inherited]
 

Returns the number of bytes available on the socket connection.

Exceptions:
none 
Returns:
UInt32 The number of available bytes.

bool CP_Socket::HasBytesAvailable  )  const [inherited]
 

Returns if there are bytes available at the socket connection.

Exceptions:
none 
Returns:
bool const true if there are bytes available

UInt32 CP_Socket::GetHostByName const CP_String inHostName  )  [static, inherited]
 

Returns the host from the passed in host name.

Parameters:
inHostName Name of the host to return.
Exceptions:
OSError exceptions.
Returns:
UInt32 The host returned from the host name.

CP_NetworkAddress CP_Socket::GetHostAddressByName const CP_String inHostName  )  [static, inherited]
 

Returns the host from the passed in host name.

Parameters:
inHostName Name of the host to return.
Exceptions:
OSError exceptions.
Returns:
CP_NetworkAddress The host returned from the host name.

UInt32 CP_Socket::GetAddress  )  const [inherited]
 

Return an UInt32 containing the address we are communicating over.

Exceptions:
none 
Returns:
UInt32 The return address.

CP_NetworkAddress CP_Socket::GetNetworkAddress  )  const [inherited]
 

Return an GetNetworkAddress containing the address we are communicating over.

Exceptions:
none 
Returns:
GetNetworkAddress The return address.

UInt32 CP_Socket::GetPeerAddress  )  const [inherited]
 

Return an UInt32 containing the peer address we are communicating with.

Exceptions:
none 
Returns:
UInt32 The return peer address.

CP_NetworkAddress CP_Socket::GetPeerNetworkAddress  )  const [inherited]
 

Return a CP_NetworkAddress containing the peer address we are communicating with.

Exceptions:
none 
Returns:
CP_NetworkAddress The return peer address.

UInt16 CP_Socket::GetPort  )  const [inherited]
 

Returns the port we are communicating over.

Exceptions:
none 
Returns:
UInt16 The port we are communicating over.

UInt16 CP_Socket::GetPeerPort  )  const [inherited]
 

Returns the port of the peer are communicating with.

Exceptions:
none 
Returns:
UInt16 The peer port we are communicating with.

CP_String CP_Socket::GetHostName  )  [inherited]
 

Returns the name of the host as a string.

Exceptions:
none 
Returns:
CP_String The name of the host.

UInt32 CP_Socket::GetHostID  )  [inherited]
 

Return an UInt32 containing the peer address we are communicating with.

Exceptions:
none 
Returns:
UInt32 The return peer address.

void CP_Socket::Close  )  [inherited]
 

Closes the connection to the socket.

Exceptions:
none 
Returns:
void

void CP_Socket::CloseInput  )  [inherited]
 

Closes the input connection of the socket.

Exceptions:
none 
Returns:
void

void CP_Socket::CloseOutput  )  [inherited]
 

Closes the output connection of the socket.

Exceptions:
none 
Returns:
void

bool CP_Socket::IsConnected char  rdwr = -1  )  const [inherited]
 

Return true if we have a current connection.

Exceptions:
none 
Returns:
bool True if we have a connection.

bool CP_Socket::IsConnectionClosed UInt32  inTimeoutInMicroseconds = 10000  )  const [inherited]
 

Returns if the connection has closed.

Parameters:
inTimeoutInMicroseconds The call will return within this timeout
Exceptions:
none 
Returns:
bool const true if connection is closes

void CP_Socket::Initialize void   )  [protected, inherited]
 

Initializes the socket members called from every constructor.

Exceptions:
OSError exceptions.

void CP_Socket::GetConnectedSocketInfo void   )  [protected, inherited]
 


Member Data Documentation

bool CP_ServerSocket::fListening [private]
 

CP_String CP_Socket::fHostName [protected, inherited]
 

char CP_Socket::fIsConnected [protected, inherited]
 

CP_String containing the name of the host.

sockaddr_in CP_Socket::fSocketAddress [protected, inherited]
 

flag to indicate if we are currently connected.

hostent* CP_Socket::fnlp_host [protected, inherited]
 

a sockaddr_in structure with the current address info.

int CP_Socket::fSocketDescriptor [protected, inherited]
 

SOCKET CP_Socket::fSocketDescriptor [protected, inherited]
 

CP_NetworkAddress CP_Socket::fConnectedSocketAddress [protected, inherited]
 

UInt16 CP_Socket::fConnectedSocketPort [protected, inherited]
 

CP_NetworkAddress CP_Socket::fConnectedPeerAddress [protected, inherited]
 

UInt16 CP_Socket::fConnectedPeerPort [protected, inherited]
 


The documentation for this class was generated from the following files:
Generated on Sat Sep 17 20:02:12 2005 for CPLAT by  doxygen 1.4.0