ERC CISST - cisst software

osaSocket Class Reference

Inheritance diagram for osaSocket:

Inheritance graph
[legend]
Collaboration diagram for osaSocket:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 157 of file osaSocket.h.

Public Types

Public Member Functions

Static Public Member Functions

Protected Member Functions

Protected Attributes

Friends


Constructor & Destructor Documentation

osaSocket::osaSocket ( void *  socketFDPtr  )  [protected]

osaSocketServer constructor (for use by osaSocketServer)

Parameters:
Void pointer is used to her avoid including WinSock2.h, the pointer is cast to proper socket in cpp file.


Member Function Documentation

int osaSocket::GetIdentifier ( void   )  const [inline]

Returns:
Socket file descriptor

Definition at line 185 of file osaSocket.h.

static std::string osaSocket::GetLocalhostIP ( void   )  [static]

Returns:
The first IP address of the localhost as a string

static int osaSocket::GetLocalhostIP ( std::vector< std::string > &  IPaddress  )  [static]

Retrieve IP address of the localhost as string from each network interface (which may be more than two).

Parameters:
IPaddresses container for IP address as string
Returns:
Number of IP address retrieved with IPaddresses filled

void osaSocket::SetDestination ( const std::string &  host,
unsigned short  port 
)

Set the destination address for UDP or TCP socket.

Parameters:
host Server's hostname or IP address (e.g. localhost, 127.0.0.1)
port Server's port number

bool osaSocket::Connect ( void   ) 

Connect to the server; required for TCP sockets and should be used after SetDestination().

Returns:
true if the connection was successful

bool osaSocket::Connect ( const std::string &  host,
unsigned short  port 
)

Connect to the server; required for TCP sockets; includes call to SetDestination().

Parameters:
host Server's hostname or IP address (e.g. localhost, 127.0.0.1)
port Server's port number
Returns:
true if the connection was successful

int osaSocket::Send ( const char *  bufsend,
unsigned int  msglen,
const double  timeoutSec = 0.0 
)

Send a byte array via the socket.

Parameters:
bufsend Buffer holding bytes to be sent
msglen Number of bytes to send
timeoutSec is the longest time we should wait to send something (NA for UDP)
Returns:
Number of bytes sent (-1 if error)
Note:
Since this is a nonblocking call the socket might not be ready to send right away so a short timeout will help in cases when large amount of data is sent around. If the socket is not ready within the timeout then the connection will be closed

int osaSocket::Send ( const std::string &  bufsend  )  [inline]

Send a string via the socket.

Parameters:
bufsend String to be sent
Returns:
Number of bytes sent (-1 if error)

Definition at line 232 of file osaSocket.h.

int osaSocket::Receive ( char *  bufrecv,
unsigned int  maxlen,
const double  timeoutSec = 0.0 
)

Receive a byte array via the socket.

Parameters:
bufrecv Buffer to store received data
maxlen Maximum number of bytes to receive
timeoutSec Timeout in seconds. (NA for UDP)
Returns:
Number of bytes received. 0 if timeout is reached and/or no data is received.

bool osaSocket::Close ( void   ) 

Close the socket.

Returns:
False if close fails

bool osaSocket::IsConnected ( void   ) 

\ brief Connection state (only works for TCP)

Returns:
Returns true if the socket thinks it is connected

unsigned long osaSocket::GetIP ( const std::string &  host  )  const [protected]

Returns:
IP address (as a number) for the given host


The documentation for this class was generated from the following file:
erc-cisst-devel<at>lists.johnshopkins.edu