Server socket.
More...
#include <C:/Users/Andres/source/repos/casm_viewer/external/tinc/external/allolib/include/al/io/al_Socket.hpp>
|
| SocketServer (uint16_t port, const char *address="", 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) |
|
Server socket.
A server socket typically waits and listens for incoming socket connections. After accepting an incoming connection, data is received and possibly sent through the accepted socket.
Definition at line 215 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.
◆ SocketServer()
al::SocketServer::SocketServer |
( |
uint16_t |
port, |
|
|
const char * |
address = "" , |
|
|
al_sec |
timeout = 0 , |
|
|
int |
type = UDP | DGRAM |
|
) |
| |
|
inline |
- Parameters
-
[in] | port | Local port number (valid range is 0-65535) |
[in] | address | Local IP address. If empty, will bind all network interfaces to socket. |
[in] | timeout | < 0 is block forever, 0 is no blocking, > 0 is block with timeout |
[in] | type | Protocol type |
Definition at line 225 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: