LRAUV  revA
SocketClient Class Reference

Implements a Socket client for communicating with SocketServer instances. More...

#include <SocketClient.h>

Inheritance diagram for SocketClient:
Collaboration diagram for SocketClient:

Public Member Functions

 SocketClient (const char *host, int port) throw ( SocketException )
 
 SocketClient (const char *host, int port, int timeoutMillis) throw ( SocketException )
 Connection with timeout. More...
 
virtual ~SocketClient ()
 
- Public Member Functions inherited from Socket
virtual ~Socket ()
 
int send (const char *buffer, size_t bufferLength) const throw ( SocketException& )
 If return value is -1, check errno. More...
 
int sendall (const char *buffer, size_t bufferLength)
 Like send but making sure the whole requested buffer is sent out. More...
 
int recv (char *buffer, size_t bufferLength) const throw ( SocketException& )
 Blocking read. More...
 
int recv (char *buffer, size_t bufferLength, int timeoutMillis) throw ( SocketException& )
 Socket read with timeout. More...
 
int setTimeout (const int milliseconds)
 
int close ()
 
int getPort ()
 
int getDescriptor ()
 exposes the socket descriptor to facilitate direct operations More...
 

Additional Inherited Members

- Protected Member Functions inherited from Socket
 Socket ()
 
void create () throw ( SocketException& )
 
void bind (const int port) throw ( SocketException& )
 
void listen () const throw ( SocketException& )
 
void accept (Socket &newSocket) throw ( SocketException& )
 
void accept (Socket &newSocket, int timeoutMillis) throw ( SocketException& )
 accept with given timeout, which could be 0 for completely non-blocking behavior More...
 
void connect (const char *host, const int port) throw ( SocketException& )
 
void connect (const char *host, const int port, int timeoutMillis) throw ( SocketException& )
 connect with timeout. More...
 
void setNonBlocking (const bool nonBlocking) throw ( SocketException& )
 
bool isValid () const
 
void setTimeval (const int milliseconds, struct timeval &tv)
 

Detailed Description

Implements a Socket client for communicating with SocketServer instances.

Constructor & Destructor Documentation

SocketClient::SocketClient ( const char *  host,
int  port 
)
throw (SocketException
)
SocketClient::SocketClient ( const char *  host,
int  port,
int  timeoutMillis 
)
throw (SocketException
)

Connection with timeout.

According to man connect, the implementation is based on the following sequence of system calls as needed:

  • fcntl (to put socket in non-blocking mode)
  • connect
  • select (called if connect fails with EINPROGRESS)
  • getsockopt (called to verify that socket is OK when select indicates socket is "ready")

The timeout parameter is used in the select system call.

Parameters
host
port
timeoutMillisTimeout in millis. A value of 100 or more has worked well according to testing with client on testhyssim and server on bufflehead.
Exceptions
SocketExceptionIf some error occurs. In particular, the thrown exception will have getErrno() == EAGAIN if one of the following occurs:
  • connection refused (No-one listening on the remote address)
  • timeout while trying to connect

References Socket::connect(), and Socket::create().

virtual SocketClient::~SocketClient ( )
inlinevirtual

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