ASL
Socket Class Reference

Detailed Description

A communication socket for the TCP/IP protocol.

#include <Socket.h>

Inheritance diagram for Socket:
LocalSocket PacketSocket TlsSocket MulticastSocket

Public Member Functions

bool disconnected ()
 Checks if the connection was lost.
 
bool connected ()
 Checks if the connection is open.
 
bool bind (const String &ip, int port)
 Binds this socket to the given IP address and port number.
 
bool bind (int port)
 Binds this socket with the given port number to all IPv4 interfaces.
 
void listen (int n=5)
 Makes this socket listen to incoming connections.
 
Socket accept ()
 For a listening socket, waits for an incoming connection and returns a socket to communicate with the remote peer.
 
InetAddress remoteAddress () const
 Returns the adress of the remote peer for a connected socket.
 
InetAddress localAddress () const
 Returns the adress of this connected socket if bound.
 
bool connect (const String &host, int port)
 Connects this socket to the given host name and port, trying all addresses assigned to that name until one succeeds.
 
bool connect (const String &host)
 Connects this socket to the given address given as a string "host:port" or "[ipv6]:port".
 
void close ()
 Closes this socket.
 
String readLine ()
 Reads a line of text from the socket (keep in mind this is not buffered, can be a bit inefficient, and there is a length limit of 8000 bytes)
 
int available ()
 Returns the number of bytes available for reading without blocking.
 
int read (void *data, int size)
 Reads size bytes from the socket into the bufffer pointed to by data.
 
int write (const void *data, int n)
 Writes n bytes from the bufffer pointed to by data to the socket.
 
int write (const ByteArray &data)
 Writes the byte array to the socket and returns the number of bytes actually sent.
 
ByteArray read (int n=-1)
 Reads n bytes and returns them as an array of bytes, or reads all available bytes if no argument is given.
 
void skip (int n)
 Skips (reads and discards) the next n bytes from the socket.
 
bool waitInput (double timeout=2)
 Waits until there is incoming data in the socket or it is disconnected for a maximum time, and returns true if some of that happened before timeout.
 
bool waitData (double timeout=2)
 Waits until there is incoming data in the socket or it is disconnected for a maximum time, and returns true only if there is data to read (false may mean no data or disconnection)
 
int error () const
 Returns true if there was some communication error in this socket.
 
String errorMsg () const
 Returns a string representation of the last socket error.
 
template<class T >
Socketoperator<< (const T &x)
 Writes variable x to the socket respecting endianness in binary form.
 
template<class T >
Socketoperator>> (T &x)
 Reads variable x from the socket respecting endianness in binary form.
 
String readString (int n)
 Reads n bytes from the socket a string.
 
Socketoperator>> (String &x)
 Reads a string from the socket that is preceded by its length as an int32 (the sender must send the byte length before) More...
 

Member Function Documentation

◆ operator>>()

Socket& operator>> ( String x)

Reads a string from the socket that is preceded by its length as an int32 (the sender must send the byte length before)

Deprecated:
Too specific

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