Provides an asynchronous network wrapper. It contains functions for creating both servers and clients (called streams).
Procs
proc onConnection=(server: TcpServer; cb: proc (stream: TcpStream) {.
closure, gcsafe.}) {.raises: [], tags: [].}- Source Edit
proc onClose=(server: TcpServer; cb: proc (err: ref NodeError) {.
closure, gcsafe.}) {.raises: [], tags: [].}- Source Edit
proc close(server: TcpServer) {.
raises: [Exception, NodeError], tags: [RootEffect].}- Close server to close the file descriptors and release internal resources. Source Edit
proc newTcpServer(maxConnections = 1024): TcpServer {.
raises: [Exception, NodeError], tags: [RootEffect].}- Create a new TCP server. Source Edit
proc serve(server: TcpServer; port: Port; hostname = "127.0.0.1"; backlog = 511; domain = Domain.AF_INET) {.
raises: [Exception, NodeError], tags: [RootEffect].}-
Start the process of listening for incoming TCP connections on the specified hostname and port.
backlog specifies the length of the queue for pending connections. When the queue fills, new clients attempting to connect fail with ECONNREFUSED until the server calls accept to accept a connection from the queue.
Source Edit