The Ioto agent provides a cross platform Socket abstraction to make network programming easier and simpler.
The Socket API is fiber aware in that blocking API calls will transparently resume other waiting fibers while waiting for I/O. This enables a simple, straight-line procedural programming style without ugly callbacks or complex threads. See Fiber Coroutines for more details.
All the socket APIs must be called from a fiber.
First you need a socket object. To allocate a socket object:
To connect to a host or IP address:
Listening for Connections
To listen for connections:
The second argument is the IP address(s) on which to bind. If NULL, the socket listens on all interfaces.
Testing the Socket
To test if the socket is closed:
To test for end-of-file. i.e. if the peer has closed the other end of the socket:
To determine if a socket is using TLS. i.e. is secure:
Closing the Socket
To close a socket:
To read from a socket. The read call will return with whatever bytes are available. If none is available, this call will block and yield the current fiber and resume another fiber. When data is available, the call will resume.
Set the deadline to zero to use the Ioto default deadline timeout which is infinite.
To write to a socket:
To write a block of data to a socket, use rWriteSocket. If the socket is in non-blocking mode (the default), the write may return having written less than the required bytes. If no data can be written, this call will yield the current fiber and resume another fiber. When data is available, the call will resume.
To configure the socket TLS certificates, use rSetSocketCerts:
To select the preferred ciphers:
To control how the Socket will verify peers:
The full API is specified here: