|
Allolib
1.0
C++ Components For Interactive Multimedia
|
#include <C:/Users/Andres/source/repos/casm_viewer/external/tinc/external/allolib/include/al/io/al_Socket.hpp>
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 | |
| Socket () | |
| Create uninitialized socket. | |
| Socket (uint16_t port, const char *address, al_sec timeout, int type) | |
| 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. | |
| 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... | |
| void | timeout (al_sec t) |
| Set socket timeout. 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 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 () |
A network socket
Definition at line 58 of file al_Socket.hpp.
| anonymous enum |
Bit masks for specifying a transmission protocol.
Definition at line 61 of file al_Socket.hpp.
| al::Socket::Socket | ( | uint16_t | port, |
| const char * | address, | ||
| al_sec | timeout, | ||
| int | type | ||
| ) |
| [in] | port | Port number (valid range is 0-65535) |
| [in] | address | IP address |
| [in] | timeout | < 0 is block forever, 0 is no blocking, > 0 is block with timeout |
| [in] | type | Protocol type |
| bool al::Socket::accept | ( | Socket & | sock | ) |
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.
| bool al::Socket::connect | ( | ) |
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.
| bool al::Socket::listen | ( | ) |
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.
| size_t al::Socket::recv | ( | char * | buffer, |
| size_t | maxlen, | ||
| char * | from = nullptr |
||
| ) |
Read data from a network.
| [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 |
The from pointer should be at least the size of Message::mSenderAddr
| size_t al::Socket::send | ( | const char * | buffer, |
| size_t | len | ||
| ) |
Send data over a network.
| [in] | buffer | The buffer of data to send |
| [in] | len | The length, in bytes, of the buffer |
| void al::Socket::timeout | ( | al_sec | t | ) |
Set socket timeout.
This timeout applies to send/recv, accept, and connect calls.
| [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. |