YGP::Socket Class Reference

A socket is a generalized interprocess communication channel, which supports communication between unrelated processes, and even between processes running on different machines that communicate over a network. More...

List of all members.

Public Member Functions

 Socket () throw (YGP::CommError)
 Socket (int socket)
 Socket (unsigned int port) throw (YGP::CommError)
 Socket (const char *server, unsigned int port) throw (YGP::CommError)
 Socket (const std::string &server, unsigned int port) throw (YGP::CommError)
 Socket (const Socket &other)
virtual ~Socket ()
Socketoperator= (const Socket &other) throw (YGP::CommError)
Socketoperator= (int socket)
void listenAt (unsigned int port) const throw (YGP::CommError)
int waitForInput () const throw (YGP::CommError)
int read (std::string &input) const throw (YGP::CommError)
int read (char *pBuffer, unsigned int lenBuffer) const throw (YGP::CommError)
void writeTo (const std::string &server, unsigned int port) const throw (YGP::CommError)
void writeTo (const char *server, unsigned int port) const throw (YGP::CommError)
void write (const std::string &output) const throw (YGP::CommError)
void write (const char *pBuffer) const throw (YGP::CommError)
void write (const char *pBuffer, unsigned int lenBuffer) const throw (YGP::CommError)
int number () const
 operator int () const

Static Public Member Functions

static unsigned int getPortOfService (const char *service) throw (YGP::CommError)

Static Protected Member Functions

static void throwError (const std::string &error, int errNum) throw (YGP::CommError)


Detailed Description

A socket is a generalized interprocess communication channel, which supports communication between unrelated processes, and even between processes running on different machines that communicate over a network.

This class provides methods to connect to, read from and write to another socket.

At the moment the communications are always handled using streamed connections in the Internet namespace.

Deprecated:
Please use boost::asio

Constructor & Destructor Documentation

YGP::Socket::Socket (  )  throw (YGP::CommError)

Defaultconstructor; creates an socket but without any connection.

Exceptions:
YGP::CommError in case of a communication error

YGP::Socket::Socket ( int  socket  )  [inline]

Constructor from system socket.

YGP::Socket::Socket ( unsigned int  port  )  throw (YGP::CommError)

Constructor; creates an socket which waits for input on port.

Parameters:
port Port to listen at
Exceptions:
YGP::CommError in case of a communication error

YGP::Socket::Socket ( const char *  server,
unsigned int  port 
) throw (YGP::CommError)

Constructor; creates an socket which tries to write to server using the passed port.

Parameters:
server Name (or number) of server to send to
port Port to write to
Exceptions:
YGP::CommError in case of a communication error

YGP::Socket::Socket ( const std::string &  server,
unsigned int  port 
) throw (YGP::CommError)

Constructor; creates an socket which tries to write to server using the passed port.

Parameters:
server Name (or number) of server to send to
port Port to write to
Exceptions:
YGP::CommError in case of a communication error

YGP::Socket::Socket ( const Socket other  )  [inline]

Copy constructor.

YGP::Socket::~Socket (  )  [virtual]

Destructor.


Member Function Documentation

unsigned int YGP::Socket::getPortOfService ( const char *  service  )  throw (YGP::CommError) [static]

Retrieves the port-number of the passed textual port-description (service name or number as text).

Parameters:
service Text describing port
Returns:
unsigned int Number of the passed service
Exceptions:
YGP::CommError in case of an invalid input

void YGP::Socket::listenAt ( unsigned int  port  )  const throw (YGP::CommError)

Specifies the port to listen at (for incoming connections).

Parameters:
port Port at which to listen
Exceptions:
YGP::CommError in case of a communication error

int YGP::Socket::number (  )  const [inline]

Convertion from a Socket to a system socket (represented by an integer).

YGP::Socket::operator int (  )  const [inline]

Convertion from a Socket to a system socket (represented by an integer).

Socket & YGP::Socket::operator= ( int  socket  ) 

Assignmentoperator; creates an socket out of a system-socket.

Parameters:
socket,: Socket to assign
Returns:
Socket& Reference to self

Socket & YGP::Socket::operator= ( const Socket rhs  )  throw (YGP::CommError)

Assignment-operator; duplicates a socket.

The old socket is closed.

Parameters:
rhs Socket to assign
Returns:
Socket& Reference to self
Exceptions:
YGP::CommError in case of a communication error

int YGP::Socket::read ( char *  pBuffer,
unsigned int  lenBuffer 
) const throw (YGP::CommError)

Reads up to lenBuffer bytes data into the buffer specified by pBuffer from the previously specified source.

Parameters:
pBuffer Pointer to buffer receiving the input
lenBuffer Length of that buffer
Returns:
int Number of bytes read
Exceptions:
YGP::CommError in case of a communication error

int YGP::Socket::read ( std::string &  input  )  const throw (YGP::CommError)

Reads all available data into the buffer specified by input from the previously specified source.

Parameters:
input String receiving the input
Returns:
int Number of bytes read
Exceptions:
YGP::CommError in case of a communication error

void YGP::Socket::throwError ( const std::string &  error,
int  errNum 
) throw (YGP::CommError) [static, protected]

Throws a domain_error with an explaining text.

Parameters:
error Text describing the error
errNum Number of error; if !=0 an explaining text is appended
Exceptions:
YGP::CommError in case of a communication error

int YGP::Socket::waitForInput (  )  const throw (YGP::CommError)

Waits until someone wants to create a (new) connection using the previously specified port.

The new (system-)socket for this communication is returned.

Technical note: If a new connection is opened to a Socket, it is actually "duplicated" and returned to enable multiple connections to one port (socket).

Returns:
int Socket over which to communicate
Exceptions:
YGP::CommError in case of a communication error

void YGP::Socket::write ( const char *  pBuffer,
unsigned int  lenBuffer 
) const throw (YGP::CommError)

Writes lenBuff bytes of the buffer pointed to by pBuffer to the socket (which must have been connected to an address).

Parameters:
pBuffer Buffer to write
lenBuffer Length of data to write
Exceptions:
YGP::CommError in case of a communication error
Precondition:
pBuffer not NULL

void YGP::Socket::write ( const char *  pBuffer  )  const throw (YGP::CommError)

Writes the contents of pBuffer up to the first zero-byte to the socket (which must have been connected to an address).

Parameters:
pBuffer Buffer to write
Exceptions:
YGP::CommError in case of a communication error
Precondition:
pBuffer not NULL

void YGP::Socket::write ( const std::string &  output  )  const throw (YGP::CommError) [inline]

Writes the content of output to the socket (which must have been connected to an address).

void YGP::Socket::writeTo ( const char *  server,
unsigned int  port 
) const throw (YGP::CommError)

Specifies the server and port to write to (for outgoing connections).

Parameters:
server Name (or number) of the server to connect to
port Portnumber to connect to
Exceptions:
YGP::CommError in case of a communication error
Precondition:
server not NULL

void YGP::Socket::writeTo ( const std::string &  server,
unsigned int  port 
) const throw (YGP::CommError) [inline]

Specifies the server and port to write to (for outgoing connections).


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

YGP Version 0.9.31 - Generated on Wed Nov 18 11:25:28 2009 by doxygen 1.5.8