Allolib  1.0
C++ Components For Interactive Multimedia
al::SocketClient Class Reference

Client socket. More...

#include <C:/Users/Andres/source/repos/casm_viewer/external/tinc/external/allolib/include/al/io/al_Socket.hpp>

Inheritance diagram for al::SocketClient:
al::Socket

Public Types

enum  {
  TCP = 6 , UDP = 17 , SCTP = 132 , STREAM = 1 << 8 ,
  DGRAM , INET = 1 << 16 , INET6 = 2 << 16
}
 Bit masks for specifying a transmission protocol. More...
 

Public Member Functions

 SocketClient (uint16_t port, const char *address="localhost", al_sec timeout=0, int type=UDP|DGRAM)
 
bool opened () const
 Returns whether socket is open.
 
const std::string & address () const
 Get IP address string.
 
uint16_t port () const
 Get port number.
 
al_sec timeout () const
 Get timeout duration, in seconds.
 
void timeout (al_sec t)
 Set socket timeout. More...
 
bool open (uint16_t port, const char *address, al_sec timeout, int type)
 Open socket (reopening if currently open)
 
void close ()
 Close the socket.
 
bool bind ()
 Bind current (local) address to socket. Called on a server socket.
 
bool connect ()
 Connect socket to current (remote) address. More...
 
size_t recv (char *buffer, size_t maxlen, char *from=nullptr)
 Read data from a network. More...
 
size_t send (const char *buffer, size_t len)
 Send data over a network. More...
 
bool listen ()
 Listen for incoming connections from remote clients. More...
 
bool accept (Socket &sock)
 Check for an incoming socket connection. More...
 
ValueSourcevalueSource ()
 

Static Public Member Functions

static std::string hostName ()
 Get name of current host.
 
static std::string hostIP ()
 IP address of current host.
 
static std::string nameToIp (std::string name)
 

Protected Member Functions

virtual bool onOpen ()
 

Detailed Description

Client socket.

A client socket connects to a remote address to which it sends data to (e.g., a request to a server) and possibly receives data from (e.g., a response from a server).

Definition at line 189 of file al_Socket.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
inherited

Bit masks for specifying a transmission protocol.

Enumerator
TCP 

Transmission Control Protocol

UDP 

User Datagram Protocol

SCTP 

Stream Control Transmission Protocol

STREAM 

Connection-based, reliable byte stream

DGRAM 

Datagram; connectionless, unreliable fixed-length messages

INET 

IPv4 Internet protocols

INET6 

IPv6 Internet protocols

Definition at line 61 of file al_Socket.hpp.

Constructor & Destructor Documentation

◆ SocketClient()

al::SocketClient::SocketClient ( uint16_t  port,
const char *  address = "localhost",
al_sec  timeout = 0,
int  type = UDP | DGRAM 
)
inline
Parameters
[in]portRemote port number (valid range is 0-65535)
[in]addressRemote IP address
[in]timeout< 0 is block forever, 0 is no blocking, > 0 is block with timeout
[in]typeProtocol type

Definition at line 198 of file al_Socket.hpp.

Member Function Documentation

◆ accept()

bool al::Socket::accept ( Socket sock)
inherited

Check for an incoming socket connection.

Accepts a received incoming attempt to create a new TCP connection from the remote client, and creates a new socket associated with the socket address pair of this connection.

◆ connect()

bool al::Socket::connect ( )
inherited

Connect socket to current (remote) address.

Called on a client socket. In case of a TCP socket, this causes an attempt to establish a new TCP connection.

◆ listen()

bool al::Socket::listen ( )
inherited

Listen for incoming connections from remote clients.

After a socket has been associated with an address, listen prepares it for incoming connections. This is only relevent for server sockets using stream-oriented connections, such as TCP.

◆ recv()

size_t al::Socket::recv ( char *  buffer,
size_t  maxlen,
char *  from = nullptr 
)
inherited

Read data from a network.

Parameters
[in]bufferA buffer to copy the received data into
[in]maxlenThe maximum length, in bytes, of data to copy
[out]fromThe sender's IP address is copied here if pointer not null
Returns
bytes read Note: to ensure receipt of all messages in the queue, use while(recv()){}

The from pointer should be at least the size of Message::mSenderAddr

◆ send()

size_t al::Socket::send ( const char *  buffer,
size_t  len 
)
inherited

Send data over a network.

Parameters
[in]bufferThe buffer of data to send
[in]lenThe length, in bytes, of the buffer
Returns
bytes sent

◆ timeout()

void al::Socket::timeout ( al_sec  t)
inherited

Set socket timeout.

This timeout applies to send/recv, accept, and connect calls.

Parameters
[in]tTimeout in seconds. If t > 0, the socket blocks with timeout t. If t = 0, the socket never blocks. If t < 0, the socket blocks forever. Note that setting the timeout will close and re-open the socket.

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