cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Functions
osaSocket.h File Reference

Declaration of osaSocketThis is a cross-platform socket library with basic support for UDP (datagram) and TCP (stream) sockets. The BSD socket API is used on Unix-like systems, while the Winsock2 API is used on Windows. More...

#include <cisstCommon/cmnAssert.h>
#include <cisstCommon/cmnGenericObject.h>
#include <cisstCommon/cmnLogger.h>
#include <cisstCommon/cmnPortability.h>
#include <cisstOSAbstraction/osaExport.h>

Go to the source code of this file.

Classes

struct  osaIPandPort
 
class  osaSocket
 

Functions

 CMN_DECLARE_SERVICES_INSTANTIATION (osaSocket)
 

Detailed Description

Declaration of osaSocket

This is a cross-platform socket library with basic support for UDP (datagram) and TCP (stream) sockets. The BSD socket API is used on Unix-like systems, while the Winsock2 API is used on Windows.

For UDP, both a server and client can be defined and set as follows:

server.AssignPort(serverPort);
client.SetDestination(serverHost, serverPort);

where serverHost could either be the hostname or the IP address of the server. UDP sockets update their destination to the origin of the last message received.

For the TCP case, the client has to additionally call the Connect() method, while the server is created using the osaSocketServer class.

client.SetDestination(serverIP, serverPort);
client.Connect();
// or
client.Connect(serverIP, serverPort);

The TCP server is defined using osaSocketServer, which calls an overloaded osaSocket constructor upon accepting a connection (see osaSocketServer class).

Note
Please refer to osAbstractionTutorial/sockets for usage examples.
Disconnection is detected when a socket attempts to write to another socket and does not received an ACK.
Todo:

GetIP() could be static or external to the osaSocket class.

Perhaps GetLocalhostIP() should be outside the class.

Function Documentation

CMN_DECLARE_SERVICES_INSTANTIATION ( osaSocket  )