class tcpsocket::Socket

A class for working with TCP sockets.

Child Classes

A class for working with TCP sockets. This class provides an interface to open a connection, send data, and receive data.

Direct child classes:
SSLSocket
BufferedSocket
ServerSocket

Inheritance:


Public Methods

[more] Socket(const Socket& s)
Copy constructor, copies the socket handle
[more] Socket()
Default constructor for the socket
[more] Socket(int socket_handle)
Constructs the socket from a socket handle
[more] Socket(const char* host, short port) throw(SocketException)
Constructs the socket and opens a connection to a server
[more]virtual Socket* clone() const
Clones this Socket object
[more]void close() throw(SocketException)
Closes the socket handle
[more]virtual int getSocket()
Provides access to the socket handle
[more]bool getThrowOnClosed()
Provides the current status of the throw on close flag
[more]Socket& operator=(const Socket& s)
Copy operator, copies the socket handle
[more]size_t receive(char* readBuffer, size_t length) throw(SocketException)
Receives data from the socket.
[more]size_t receiveSome(char* readBuffer, size_t length) throw(SocketException)
Receives data from the socket.
[more]size_t send(const char* sendBuffer, size_t length) throw(SocketException)
Sends data over the socket.
[more]void setThrowOnClosed(bool throwOnClose)
Sets a flag to throw a SocketException in the case the socket was closed durring a send or receive operation.
[more] ~Socket()
Destroys the socket.

Protected Fields

[more]int m_socket
The Socket handle

Member Documentation


Socket ()
Default constructor for the socket


Socket (int socket_handle)
Constructs the socket from a socket handle
Parameters:
socket_handle - [in] A previously created socket handle


Socket (const Socket& s)
Copy constructor, copies the socket handle
Parameters:
s - [in] The source socket


Socket& operator= (const Socket& s)
Copy operator, copies the socket handle
Parameters:
s - [in] The source socket
Returns:
A reference to this object


void setThrowOnClosed (bool throwOnClose)
Sets a flag to throw a SocketException in the case the socket was closed durring a send or receive operation. Throwing an exception on a socket close can be useful when using the insertion and extraction operators associated with the BufferedSocket class.
Parameters:
throwOnClose - [in] Flags the class to throw an exception on detecting a closed socket
See Also:
BufferedSocket


bool getThrowOnClosed ()
Provides the current status of the throw on close flag
Returns:
The status of the throw on close flag.


virtual int getSocket ()
Provides access to the socket handle
Returns:
The socket handle


virtual Socket* clone () const
Clones this Socket object
Returns:
A clone of this object.


int m_socket
The Socket handle


Socket (const char* host, short port) throw(SocketException)
Constructs the socket and opens a connection to a server
Parameters:
host - [in] The address of the server or DNS name
- port [in] The TCP port to connect to


~Socket ()
Destroys the socket. Note: does not close the socket handle


size_t send (const char* sendBuffer, size_t length) throw(SocketException)
Sends data over the socket. Sends exactly length bytes.
Throws:
SocketException if the connection was closed and the throw on close flag was set.
Parameters:
sendBuffer - [in] A buffer containing the data to be sent
length - [in] The number of bytes in the buffer
Returns:
The number of bytes sent, -1 on error, and 0 if the connection was closed


size_t receive (char* readBuffer, size_t length) throw(SocketException)
Receives data from the socket. Receives exactly length bytes or less if the socket is closed early.
Throws:
SocketException if the connection was closed and the throw on close flag was set.
Parameters:
sendBuffer - [out] A buffer receiving the data
length - [in] The maximum number of bytes in the buffer
Returns:
The number of bytes received, -1 on error, and 0 if the connection was closed


size_t receiveSome (char* readBuffer, size_t length) throw(SocketException)
Receives data from the socket. Receives upto length bytes.
Throws:
SocketException if the connection was closed and the throw on close flag was set.
Parameters:
sendBuffer - [out] A buffer receiving the data
length - [in] The maximum number of bytes in the buffer
Returns:
The number of bytes received, -1 on error, and 0 if the connection was closed


void close () throw(SocketException)
Closes the socket handle

Table of Contents HTML hierarchy of classes or Java


Safmq Documentation, copyright (c) 2004-2010 Matthew J. Battey, Licensed Under Apache License Ver 2.0
Powered By: Get SAFMQ: Store and Forward Message Queue at SourceForge.net. Fast, secure and Free Open Source software downloads