Module net

Provides an asynchronous network wrapper. It contains functions for creating both servers and clients (called streams).

Types

TcpServer = ref object
  connectionCb: proc (stream: TcpStream) {.
closure, gcsafe
.} closeCb: proc (err: ref NodeError) {.
closure, gcsafe
.} handle: TCP maxConnections: int connections: int error: ref NodeError closed: bool
Abstraction of TCP server.   Source Edit

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