Client socket.
More...
#include <C:/Users/Andres/source/repos/casm_viewer/external/tinc/external/allolib/include/al/io/al_Socket.hpp>
|
| 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...
|
|
ValueSource * | valueSource () |
|
|
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) |
|
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.
◆ anonymous enum
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.
◆ SocketClient()
al::SocketClient::SocketClient |
( |
uint16_t |
port, |
|
|
const char * |
address = "localhost" , |
|
|
al_sec |
timeout = 0 , |
|
|
int |
type = UDP | DGRAM |
|
) |
| |
|
inline |
- Parameters
-
[in] | port | Remote port number (valid range is 0-65535) |
[in] | address | Remote IP address |
[in] | timeout | < 0 is block forever, 0 is no blocking, > 0 is block with timeout |
[in] | type | Protocol type |
Definition at line 198 of file al_Socket.hpp.
◆ 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] | buffer | A buffer to copy the received data into |
[in] | maxlen | The maximum length, in bytes, of data to copy |
[out] | from | The 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] | buffer | The buffer of data to send |
[in] | len | The 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] | t | Timeout 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: