CSL  6.0
TCPServerSocket Class Reference

#include <PracticalSocket.h>

+ Inheritance diagram for TCPServerSocket:

Public Member Functions

 TCPServerSocket (unsigned short localPort, int queueLen=5) throw (SocketException)
 
 TCPServerSocket (const string &localAddress, unsigned short localPort, int queueLen=5) throw (SocketException)
 
TCPSocketaccept () throw (SocketException)
 
string getLocalAddress () throw (SocketException)
 
unsigned short getLocalPort () throw (SocketException)
 
void setLocalPort (unsigned short localPort) throw (SocketException)
 
void setLocalAddressAndPort (const string &localAddress, unsigned short localPort=0) throw (SocketException)
 

Static Public Member Functions

static void cleanUp () throw (SocketException)
 
static unsigned short resolveService (const string &service, const string &protocol="tcp")
 

Protected Attributes

int sockDesc
 

Private Member Functions

void setListen (int queueLen) throw (SocketException)
 

Detailed Description

TCP socket class for servers

Definition at line 216 of file PracticalSocket.h.

Constructor & Destructor Documentation

TCPServerSocket::TCPServerSocket ( unsigned short  localPort,
int  queueLen = 5 
)
throw (SocketException
)

Construct a TCP socket for use with a server, accepting connections on the specified port on any interface

Parameters
localPortlocal port of server socket, a value of zero will give a system-assigned unused port
queueLenmaximum queue length for outstanding connection requests (default 5)
Exceptions
SocketExceptionthrown if unable to create TCP server socket

Definition at line 253 of file PracticalSocket.cpp.

TCPServerSocket::TCPServerSocket ( const string &  localAddress,
unsigned short  localPort,
int  queueLen = 5 
)
throw (SocketException
)

Construct a TCP socket for use with a server, accepting connections on the specified port on the interface specified by the given address

Parameters
localAddresslocal interface (address) of server socket
localPortlocal port of server socket
queueLenmaximum queue length for outstanding connection requests (default 5)
Exceptions
SocketExceptionthrown if unable to create TCP server socket

Definition at line 259 of file PracticalSocket.cpp.

Member Function Documentation

TCPSocket * TCPServerSocket::accept ( )
throw (SocketException
)

Blocks until a new connection is established on this socket or error

Returns
new connection socket
Exceptions
SocketExceptionthrown if attempt to accept a new connection fails

Definition at line 266 of file PracticalSocket.cpp.

References Socket::sockDesc.

void TCPServerSocket::setListen ( int  queueLen)
throw (SocketException
)
private

Definition at line 275 of file PracticalSocket.cpp.

string Socket::getLocalAddress ( )
throw (SocketException
)
inherited

Get the local address

Returns
local address of socket
Exceptions
SocketExceptionthrown if fetch fails

Definition at line 115 of file PracticalSocket.cpp.

unsigned short Socket::getLocalPort ( )
throw (SocketException
)
inherited

Get the local port

Returns
local port of socket
Exceptions
SocketExceptionthrown if fetch fails

Definition at line 125 of file PracticalSocket.cpp.

void Socket::setLocalPort ( unsigned short  localPort)
throw (SocketException
)
inherited

Set the local port to the specified port and the local address to any interface

Parameters
localPortlocal port
Exceptions
SocketExceptionthrown if setting local port fails

Definition at line 135 of file PracticalSocket.cpp.

void Socket::setLocalAddressAndPort ( const string &  localAddress,
unsigned short  localPort = 0 
)
throw (SocketException
)
inherited

Set the local port to the specified port and the local address to the specified address. If you omit the port, a random port will be selected.

Parameters
localAddresslocal address
localPortlocal port
Exceptions
SocketExceptionthrown if setting local port or address fails

Definition at line 148 of file PracticalSocket.cpp.

References fillAddr().

void Socket::cleanUp ( )
throw (SocketException
)
staticinherited

If WinSock, unload the WinSock DLLs; otherwise do nothing. We ignore this in our sample client code but include it in the library for completeness. If you are running on Windows and you are concerned about DLL resource consumption, call this after you are done with all Socket instances. If you execute this on Windows while some instance of Socket exists, you are toast. For portability of client code, this is an empty function on non-Windows platforms so you can always include it.

Parameters
bufferbuffer to receive the data
bufferLenmaximum number of bytes to read into buffer
Returns
number of bytes read, 0 for EOF, and -1 for error
Exceptions
SocketExceptionthrown WinSock clean up fails

Definition at line 159 of file PracticalSocket.cpp.

unsigned short Socket::resolveService ( const string &  service,
const string &  protocol = "tcp" 
)
staticinherited

Resolve the specified service for the specified protocol to the corresponding port number in host byte order

Parameters
serviceservice to resolve (e.g., "http")
protocolprotocol of service to resolve. Default is "tcp".

Definition at line 167 of file PracticalSocket.cpp.

Member Data Documentation


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