4.2. Network socket library
The NETWORK module implements networking facilities including HTTP client/server
and low-level socket operations. It provides Server and Client classes
with event-driven callbacks for handling connections, requests, and responses.
All functions and symbols are in “network” module, use require to get access to it.
require network
4.2.2. Classes
- network::Server
- Fields
_server : smart_ptr< NetworkServer> - Single-socket listener that manages one client connection at a time.
- Server.make_server_adapter()
Creates a low-level server adapter bound to this Server instance.
- Server.init(port: int) : bool()
Initializes the server on the specified port; returns true on success.
- Arguments
port : int
- Server.restore(shared_orphan: smart_ptr<NetworkServer>&)
Restores the server with the given shared orphan network server pointer. This is necessary to re-establish the server state after reload of a script.
- Arguments
shared_orphan : smart_ptr< NetworkServer>&
- Server.save(shared_orphan: smart_ptr<NetworkServer>&)
Saves the server state to a shared orphan network server pointer. This is necessary to re-establish the server state after reload of a script.
- Arguments
shared_orphan : smart_ptr< NetworkServer>&
- Server.has_session() : bool()
Returns true if the server has an active client session.
- Server.is_open() : bool()
Returns true if the server is open and accepting connections.
- Server.is_connected() : bool()
Returns true if the server is currently connected to a client.
- Server.tick()
Processes pending connections and incoming data; must be called periodically.
- Server.send(data: uint8?; size: int) : bool()
Sends a data buffer to the connected client.
- Arguments
data : uint8?
size : int
- network::Server() : Server()
Constructs a new Server instance with default settings.
4.2.3. Low level NetworkServer IO
- network::make_server(class: void?; info: StructInfo const?) : bool()
Creates a new Server instance.
- Arguments
class : void? implicit
info : StructInfo? implicit
- network::server_init(server: smart_ptr<NetworkServer>; port: int) : bool()
Initializes the server to listen on the specified port.
- Arguments
server : smart_ptr< NetworkServer> implicit
port : int
- network::server_is_connected(server: smart_ptr<NetworkServer>) : bool()
Returns true if the server has an active client connection.
- Arguments
server : smart_ptr< NetworkServer> implicit
- network::server_is_open(server: smart_ptr<NetworkServer>) : bool()
Returns true if the server is listening on its bound port.
- Arguments
server : smart_ptr< NetworkServer> implicit
- network::server_restore(server: smart_ptr<NetworkServer>; class: void?; info: StructInfo const?)
Restores a server from an orphaned or interrupted state.
- Arguments
server : smart_ptr< NetworkServer> implicit
class : void? implicit
info : StructInfo? implicit
- network::server_send(server: smart_ptr<NetworkServer>; data: uint8?; size: int) : bool()
Sends data from the server to the connected client.
- Arguments
server : smart_ptr< NetworkServer> implicit
data : uint8? implicit
size : int
- network::server_tick(server: smart_ptr<NetworkServer>)
Processes pending network I/O; must be called periodically for the server to function.
- Arguments
server : smart_ptr< NetworkServer> implicit