1 #ifndef INCLUDE_AL_IO_SOCKET_HPP
2 #define INCLUDE_AL_IO_SOCKET_HPP 1
50 #include "al/system/al_Time.hpp"
51 #include "al/types/al_ValueSource.hpp"
96 static std::string nameToIp(std::string name);
147 size_t recv(
char *buffer,
size_t maxlen,
char *from =
nullptr);
154 size_t send(
const char *buffer,
size_t len);
174 virtual bool onOpen() {
return true; }
201 SocketClient::onOpen();
205 virtual bool onOpen();
228 SocketServer::onOpen();
232 virtual bool onOpen();
SocketClient(uint16_t port, const char *address="localhost", al_sec timeout=0, int type=UDP|DGRAM)
static std::string hostName()
Get name of current host.
al_sec timeout() const
Get timeout duration, in seconds.
void close()
Close the socket.
bool accept(Socket &sock)
Check for an incoming socket connection.
size_t recv(char *buffer, size_t maxlen, char *from=nullptr)
Read data from a network.
void timeout(al_sec t)
Set socket timeout.
const std::string & address() const
Get IP address string.
bool opened() const
Returns whether socket is open.
static std::string hostIP()
IP address of current host.
uint16_t port() const
Get port number.
bool bind()
Bind current (local) address to socket. Called on a server socket.
bool listen()
Listen for incoming connections from remote clients.
Socket()
Create uninitialized socket.
bool open(uint16_t port, const char *address, al_sec timeout, int type)
Open socket (reopening if currently open)
bool connect()
Connect socket to current (remote) address.
Socket(uint16_t port, const char *address, al_sec timeout, int type)
size_t send(const char *buffer, size_t len)
Send data over a network.
SocketServer(uint16_t port, const char *address="", al_sec timeout=0, int type=UDP|DGRAM)