cisst-saw
|
#include <osaSocket.h>
Public Types | |
enum | SocketTypes { UDP, TCP } |
Public Member Functions | |
osaSocket (SocketTypes type=TCP) | |
Default constructor. More... | |
~osaSocket (void) | |
Destructor. More... | |
int | GetIdentifier (void) const |
bool | AssignPort (unsigned short port) |
Sets the port of a UDP server. More... | |
void | SetDestination (const std::string &host, unsigned short port) |
Set the destination address for UDP or TCP socket. More... | |
void | SetDestination (const osaIPandPort &ip_port) |
Set the destination address for UDP or TCP socket. More... | |
bool | GetDestination (std::string &host, unsigned short &port) const |
Get the destination address for UDP or TCP socket. This is particularly useful for programs using UDP because the the Receive method automatically updates the destination based on the address from which the packet was received. Thus, subsequent Send commands will send to this address. More... | |
bool | GetDestination (osaIPandPort &ip_port) const |
Get the destination address for UDP or TCP socket. This is particularly useful for programs using UDP because the the Receive method automatically updates the destination based on the address from which the packet was received. Thus, subsequent Send commands will send to this address. More... | |
bool | Connect (void) |
Connect to the server; required for TCP sockets and should be used after SetDestination() More... | |
bool | Connect (const std::string &host, unsigned short port) |
Connect to the server; required for TCP sockets; includes call to SetDestination() More... | |
bool | Connect (const osaIPandPort &ip_port) |
Connect to the server; required for TCP sockets; includes call to SetDestination() More... | |
int | Send (const char *bufsend, unsigned int msglen, double timeoutSec=0.0) |
Send a byte array via the socket. More... | |
int | Send (const std::string &bufsend, double timeoutSec=0.0) |
Send a string via the socket. More... | |
int | SendAsPackets (const char *bufsend, unsigned int msglen, unsigned int packetSize, double timeoutSec=0.0) |
Send a byte array via the socket, possibly in multiple packets based on the specified maximum packet_size. This method can be used with both UDP and TCP, though it is intended for UDP. More... | |
int | SendAsPackets (const std::string &bufsend, unsigned int packetSize, double timeoutSec=0.0) |
Send a string via the socket, possibly in multiple packets based on the specified maximum packet_size. This method can be used with both UDP and TCP, though it is intended for UDP (only for reliable UDP connections, since there is no check for missing or out of sequence packets). More... | |
int | Receive (char *bufrecv, unsigned int maxlen, double timeoutSec=0.0) |
Receive a byte array via the socket. More... | |
int | ReceiveAsPackets (std::string &bufrecv, char *packetBuffer, unsigned int packetSize, double timeoutStartSec=0.0, double timeoutNextSec=0.0) |
Receive a string via the socket, possibly in multiple packets. This method can be used with both UDP and TCP, though it is intended for UDP (only for reliable UDP connections, since there is no check for missing or out of sequence packets). More... | |
bool | Close (void) |
Close the socket. More... | |
bool | IsConnected (void) |
![]() | |
virtual | ~cmnGenericObject (void) |
virtual const cmnClassServicesBase * | Services (void) const =0 |
bool | ReconstructFrom (const cmnGenericObject &other) |
std::string | ToString (void) const |
virtual void | ToStream (std::ostream &outputStream) const |
virtual void | ToStreamRaw (std::ostream &outputStream, const char delimiter= ' ', bool headerOnly=false, const std::string &headerPrefix="") const |
virtual bool | FromStreamRaw (std::istream &inputStream, const char delimiter= ' ') |
virtual void | SerializeRaw (std::ostream &outputStream) const |
virtual void | DeSerializeRaw (std::istream &inputStream) |
virtual cmnLogger::StreamBufType * | GetLogMultiplexer (void) const |
virtual size_t | ScalarNumber (void) const |
virtual bool | ScalarNumberIsFixed (void) const |
virtual double | Scalar (const size_t CMN_UNUSED(index)) const throw (std::out_of_range) |
virtual std::string | ScalarDescription (const size_t CMN_UNUSED(index), const std::string &CMN_UNUSED(userDescription)) const |
Static Public Member Functions | |
static std::string | GetLocalhostIP (void) |
static int | GetLocalhostIP (std::vector< std::string > &IPaddress) |
Retrieve IP address of the localhost as string from each network interface (which may be more than two) More... | |
Protected Member Functions | |
osaSocket (void *socketFDPtr) | |
osaSocketServer constructor (for use by osaSocketServer) More... | |
unsigned long | GetIP (const std::string &host) const |
Protected Attributes | |
SocketTypes | SocketType |
int | SocketFD |
bool | Connected |
Friends | |
class | osaSocketServer |
osaSocket::osaSocket | ( | SocketTypes | type = TCP | ) |
Default constructor.
osaSocket::~osaSocket | ( | void | ) |
Destructor.
|
protected |
osaSocketServer constructor (for use by osaSocketServer)
Void | pointer is used to her avoid including WinSock2.h, the pointer is cast to proper socket in cpp file. |
bool osaSocket::AssignPort | ( | unsigned short | port | ) |
Sets the port of a UDP server.
bool osaSocket::Close | ( | void | ) |
Close the socket.
bool osaSocket::Connect | ( | void | ) |
Connect to the server; required for TCP sockets and should be used after SetDestination()
bool osaSocket::Connect | ( | const std::string & | host, |
unsigned short | port | ||
) |
Connect to the server; required for TCP sockets; includes call to SetDestination()
host | Server's hostname or IP address (e.g. localhost, 127.0.0.1) |
port | Server's port number |
bool osaSocket::Connect | ( | const osaIPandPort & | ip_port | ) |
Connect to the server; required for TCP sockets; includes call to SetDestination()
ip_port | Server's hostname or IP address (e.g. localhost, 127.0.0.1) and port number |
bool osaSocket::GetDestination | ( | std::string & | host, |
unsigned short & | port | ||
) | const |
Get the destination address for UDP or TCP socket. This is particularly useful for programs using UDP because the the Receive method automatically updates the destination based on the address from which the packet was received. Thus, subsequent Send commands will send to this address.
host | Reference for returning server's IP address (e.g. "127.0.0.1") |
port | Reference for returning server's port number |
bool osaSocket::GetDestination | ( | osaIPandPort & | ip_port | ) | const |
Get the destination address for UDP or TCP socket. This is particularly useful for programs using UDP because the the Receive method automatically updates the destination based on the address from which the packet was received. Thus, subsequent Send commands will send to this address.
ip_port | Reference for returning server's IP address (e.g. "127.0.0.1") and port number |
|
inline |
|
protected |
|
static |
|
static |
Retrieve IP address of the localhost as string from each network interface (which may be more than two)
IPaddresses | container for IP address as string |
bool osaSocket::IsConnected | ( | void | ) |
\ brief Connection state (only works for TCP)
int osaSocket::Receive | ( | char * | bufrecv, |
unsigned int | maxlen, | ||
double | timeoutSec = 0.0 |
||
) |
Receive a byte array via the socket.
bufrecv | Buffer to store received data |
maxlen | Maximum number of bytes to receive |
timeoutSec | Timeout in seconds |
int osaSocket::ReceiveAsPackets | ( | std::string & | bufrecv, |
char * | packetBuffer, | ||
unsigned int | packetSize, | ||
double | timeoutStartSec = 0.0 , |
||
double | timeoutNextSec = 0.0 |
||
) |
Receive a string via the socket, possibly in multiple packets. This method can be used with both UDP and TCP, though it is intended for UDP (only for reliable UDP connections, since there is no check for missing or out of sequence packets).
bufrecv | String to store received data |
packetBuffer | Buffer to store one packet |
packetSize | Maximum packet size, should equal sizeof(packetBuffer) |
timeoutStartSec | Timeout for receiving first packet, in seconds |
timeoutNextSec | Timeout for receiving subsequent packets (after first), in seconds |
int osaSocket::Send | ( | const char * | bufsend, |
unsigned int | msglen, | ||
double | timeoutSec = 0.0 |
||
) |
Send a byte array via the socket.
bufsend | Buffer holding bytes to be sent |
msglen | Number of bytes to send |
timeoutSec | is the longest time we should wait to send something |
int osaSocket::Send | ( | const std::string & | bufsend, |
double | timeoutSec = 0.0 |
||
) |
Send a string via the socket.
bufsend | String to be sent |
timeoutSec | is the longest time we should wait to send something |
int osaSocket::SendAsPackets | ( | const char * | bufsend, |
unsigned int | msglen, | ||
unsigned int | packetSize, | ||
double | timeoutSec = 0.0 |
||
) |
Send a byte array via the socket, possibly in multiple packets based on the specified maximum packet_size. This method can be used with both UDP and TCP, though it is intended for UDP.
bufsend | Buffer holding bytes to be sent |
packetSize | Maximum packet size |
timeoutSec | is the longest time we should wait to send something |
int osaSocket::SendAsPackets | ( | const std::string & | bufsend, |
unsigned int | packetSize, | ||
double | timeoutSec = 0.0 |
||
) |
Send a string via the socket, possibly in multiple packets based on the specified maximum packet_size. This method can be used with both UDP and TCP, though it is intended for UDP (only for reliable UDP connections, since there is no check for missing or out of sequence packets).
bufsend | String to be sent |
packetSize | Maximum packet size |
timeoutSec | is the longest time we should wait to send something |
void osaSocket::SetDestination | ( | const std::string & | host, |
unsigned short | port | ||
) |
Set the destination address for UDP or TCP socket.
host | Server's hostname or IP address (e.g. localhost, 127.0.0.1) |
port | Server's port number |
void osaSocket::SetDestination | ( | const osaIPandPort & | ip_port | ) |
Set the destination address for UDP or TCP socket.
ip_port | Server's hostname or IP address (e.g. localhost, 127.0.0.1) and port number |
|
friend |
|
protected |
|
protected |
|
protected |