CTCPSocket Class Reference

#include <TCPSocket.h>

Collaboration diagram for CTCPSocket:

Collaboration graph
[legend]

List of all members.

Public Member Functions

void closeSocket ()
 CTCPSocket (const std::string &address, int nPort, bool isServer=false, int nTimeoutMilliSec=0)
bool isConnected ()
bool openSocket ()
int receive (char *pBuffer, int nMaxSize)
int send (const std::string &data) const
int send (const char *pData, int nSize) const
bool setNonBlocking (int nTimeoutMilliSec)
 ~CTCPSocket ()

Public Attributes

const int PORT

Private Attributes

sockaddr_in address
bool bInitialised
const bool IS_SERVER_SOCKET
const int LISTEN_BACKLOG
std::string remoteAddress
SOCKET server_listen_socket
SOCKET tcp_socket
int timeout


Detailed Description

Definition at line 56 of file TCPSocket.h.


Constructor & Destructor Documentation

CTCPSocket::CTCPSocket ( const std::string &  address,
int  nPort,
bool  isServer = false,
int  nTimeoutMilliSec = 0 
)

Constructor of the CTCPSocket class.

Parameters:
address the address of the server to connect to (not used if isServer is true)
nPort the port number to connect to or to listen on
isServer whether to create a listening or a connecting socket
nTimeoutMilliSec if < 0 socket is blocking, if = 0 socket is nonBlocking, if > 0 a timeout is set on the socket

Definition at line 45 of file TCPSocket.cpp.

References PORT.

CTCPSocket::~CTCPSocket (  ) 

Definition at line 69 of file TCPSocket.cpp.

References closeSocket().


Member Function Documentation

void CTCPSocket::closeSocket (  ) 

Closes all sockets and resets the initialisation status.

Definition at line 174 of file TCPSocket.cpp.

References bInitialised, IS_SERVER_SOCKET, server_listen_socket, and tcp_socket.

Referenced by openSocket(), NetworkViewer::ReadDatagrams(), and ~CTCPSocket().

bool CTCPSocket::isConnected (  ) 

Returns the connection status of the socket.

Returns:
true if the socket is connected and false if not.

Definition at line 243 of file TCPSocket.cpp.

References bInitialised.

Referenced by NVRemoteConnection::isConnected(), NetworkViewer::NetworkSetup(), and NetworkViewer::ReadDatagrams().

bool CTCPSocket::openSocket (  ) 

Opens the connection to the server or listens on the specified port until a connection is established. In the second case the first connection which was accepted is used for communication.

Returns:
true if the connection was successfully established, false if an error occured

Definition at line 79 of file TCPSocket.cpp.

References address, bInitialised, closeSocket(), INVALID_SOCKET, IS_SERVER_SOCKET, LISTEN_BACKLOG, PORT, remoteAddress, server_listen_socket, setNonBlocking(), tcp_socket, and timeout.

Referenced by NVRemoteConnection::connect(), and NetworkViewer::NetworkSetup().

int CTCPSocket::receive ( char *  pBuffer,
int  nMaxSize 
)

Receives data from over the connection and stores it in the buffer pBuffer which is of the maximum size nMaxSize.

Parameters:
pBuffer buffer to store the recieved data in
nMaxSize maximum size of the buffer pBuffer
Returns:
number of bytes recieved if data was available, zero if the connection was closed or -1 on error.

Definition at line 271 of file TCPSocket.cpp.

References bInitialised, and tcp_socket.

Referenced by NetworkViewer::ReadDatagrams(), and NVRemoteConnection::receiveAnswer().

int CTCPSocket::send ( const std::string &  data  )  const

Send the content of the string. Uses CTCPSocket::send() internally.

Parameters:
data The data in string form to send.
Returns:
number of bytes sent or -1 on error.
Warning:
The number of bytes sent should be checked against the original size of data.

Definition at line 265 of file TCPSocket.cpp.

References send().

int CTCPSocket::send ( const char *  pData,
int  nSize 
) const

Send the content of the buffer pData of the given size nSize.

Parameters:
pData buffer containing the information to send
nSize the size of the buffer pData
Returns:
number of bytes sent or -1 on error.
Warning:
The number of bytes sent should be checked against the original size of pData.

Definition at line 249 of file TCPSocket.cpp.

References bInitialised, and tcp_socket.

Referenced by NetworkViewer::executeCommands(), NVRemoteConnection::getListForCommand(), NVRemoteConnection::getValueForCommand(), NVRemoteConnection::getVectorForCommand(), NVRemoteConnection::scheduleOde(), send(), NVRemoteConnection::set3DVectorForCommandAndNode(), and NVRemoteConnection::setValueForCommandAndNode().

bool CTCPSocket::setNonBlocking ( int  nTimeoutMilliSec  ) 

Sets the blocking mode of the socket. If the value is smaller than zero the socket is set to blocking mode. If the value is equal to zero the socket is set to nonblocking mode and for values greater than zero a timeout is set on the socket.

Parameters:
nTimeoutMilliSec length of the timeout in milliseconds

Definition at line 195 of file TCPSocket.cpp.

References tcp_socket.

Referenced by openSocket(), and NVRemoteConnection::receiveAnswer().


Member Data Documentation

sockaddr_in CTCPSocket::address [private]

Address structure needed for the socket system calls.

Definition at line 143 of file TCPSocket.h.

Referenced by openSocket().

bool CTCPSocket::bInitialised [private]

Is set to true if the socket was initialised correctly and a connection was established.

Definition at line 149 of file TCPSocket.h.

Referenced by closeSocket(), isConnected(), openSocket(), receive(), and send().

const bool CTCPSocket::IS_SERVER_SOCKET [private]

Stores if the socket is used in client or server mode.

Definition at line 150 of file TCPSocket.h.

Referenced by closeSocket(), and openSocket().

const int CTCPSocket::LISTEN_BACKLOG [private]

The backlog for the listen() system call.

Definition at line 147 of file TCPSocket.h.

Referenced by openSocket().

const int CTCPSocket::PORT

The port number the socket connects to or is listening on.

Definition at line 139 of file TCPSocket.h.

Referenced by CTCPSocket(), NetworkViewer::NetworkSetup(), and openSocket().

std::string CTCPSocket::remoteAddress [private]

The name or ip address of the remote host if in client mode.

Definition at line 144 of file TCPSocket.h.

Referenced by openSocket().

The socket used to listen on the specified port if in server mode. This is the same descriptor as tcp_socket first but after accepting a connection the new descriptor gets stored in tcp_socket.

Definition at line 153 of file TCPSocket.h.

Referenced by closeSocket(), and openSocket().

SOCKET CTCPSocket::tcp_socket [private]

The socket used to send and receive data.

Definition at line 152 of file TCPSocket.h.

Referenced by closeSocket(), openSocket(), receive(), send(), and setNonBlocking().

int CTCPSocket::timeout [private]

The timout in milliseconds.

Definition at line 146 of file TCPSocket.h.

Referenced by openSocket().


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

Get IPSA - Inventor Physics Simulation API at SourceForge.net. Fast, secure and Free Open Source software downloads
Generated on Sat Mar 10 20:00:19 2012 for IPSA by  doxygen 1.5.8