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 () |
Socket & | operator= (const Socket &other) throw (YGP::CommError) |
Socket & | operator= (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) |
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.
YGP::Socket::Socket | ( | ) | throw (YGP::CommError) |
Defaultconstructor; creates an socket but without any connection.
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
.
port | Port to listen at |
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
.
server | Name (or number) of server to send to | |
port | Port to write to |
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
.
server | Name (or number) of server to send to | |
port | Port to write to |
YGP::CommError | in case of a communication error |
YGP::Socket::Socket | ( | const Socket & | other | ) | [inline] |
Copy constructor.
YGP::Socket::~Socket | ( | ) | [virtual] |
Destructor.
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).
service | Text describing port |
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).
port | Port at which to listen |
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 | ) |
Socket & YGP::Socket::operator= | ( | const Socket & | rhs | ) | throw (YGP::CommError) |
Assignment-operator; duplicates a socket.
The old socket is closed.
rhs | Socket to assign |
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.
pBuffer | Pointer to buffer receiving the input | |
lenBuffer | Length of that buffer |
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.
input | String receiving the input |
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.
error | Text describing the error | |
errNum | Number of error; if !=0 an explaining text is appended |
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).
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).
pBuffer | Buffer to write | |
lenBuffer | Length of data to write |
YGP::CommError | in case of a communication error |
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).
pBuffer | Buffer to write |
YGP::CommError | in case of a communication error |
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).
server | Name (or number) of the server to connect to | |
port | Portnumber to connect to |
YGP::CommError | in case of a communication error |
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).