Janet 1.13.1-392d5d5 Documentation
(Other Versions:
1.12.2
1.11.1
1.10.1
1.9.1
1.8.1
1.7.0
1.6.0
1.5.1
1.5.0
1.4.0
1.3.1
)
Net Module
Index
net/accept net/accept-loop net/address net/chunk net/close net/connect net/flush net/listen net/read net/recv-from net/send-to net/server net/write
net/accept cfunction
(net/accept stream &opt timeout) Get the next connection on a server stream. This would usually be called in a loop in a dedicated fiber. Takes an optional timeout in seconds, after which will return nil. Returns a new duplex stream which represents a connection to the client.Community Examples
net/accept-loop cfunction
(net/accept-loop stream handler) Shorthand for running a server stream that will continuously accept new connections.Blocks the current fiber until the stream is closed, and will return the stream.Community Examples
net/address cfunction
(net/address host port &opt type) Look up the connection information for a given hostname, port, and connection type. Returns a handle that can be used to send datagrams over network without establishing a connection. On Posix platforms, you can use :unix for host to connect to a unix domain socket, where the name is given in the port argument. On Linux, abstract unix domain sockets are specified with a leading '@' character in port.Community Examples
net/chunk cfunction
(net/chunk stream nbytes &opt buf timeout) Same a net/read, but will wait for all n bytes to arrive rather than return early. Takes an optional timeout in seconds, after which will return nil.Community Examples
net/connect cfunction
(net/connect host port &opt type) Open a connection to communicate with a server. Returns a duplex stream that can be used to communicate with the server. Type is an optional keyword to specify a connection type, either :stream or :datagram. The default is :stream.Community Examples
net/flush cfunction
(net/flush stream) Make sure that a stream is not buffering any data. This temporarily disables Nagle's algorithm. Use this to make sure data is sent without delay. Returns stream.Community Examples
net/listen cfunction
(net/listen host port &opt type) Creates a server. Returns a new stream that is neither readable nor writeable. Use net/accept or net/accept-loop be to handle connections and start the server. The type parameter specifies the type of network connection, either a :stream (usually tcp), or :datagram (usually udp). If not specified, the default is :stream. The host and port arguments are the same as in net/address.Community Examples
net/read cfunction
(net/read stream nbytes &opt buf timeout) Read up to n bytes from a stream, suspending the current fiber until the bytes are available. If less than n bytes are available (and more than 0), will push those bytes and return early. Takes an optional timeout in seconds, after which will return nil. Returns a buffer with up to n more bytes in it, or raises an error if the read failed.Community Examples
net/recv-from cfunction
(net/recv-from stream nbytes buf &opt timoeut) Receives data from a server stream and puts it into a buffer. Returns the socket-address the packet came from. Takes an optional timeout in seconds, after which will return nil.Community Examples
net/send-to cfunction
(net/send-to stream dest data &opt timeout) Writes a datagram to a server stream. dest is a the destination address of the packet. Takes an optional timeout in seconds, after which will return nil. Returns stream.Community Examples
net/server function source
(net/server host port &opt handler type) Start a server asynchronously with net/listen and net/accept-loop. Returns the new server stream.Community Examples
net/write cfunction
(net/write stream data &opt timeout) Write data to a stream, suspending the current fiber until the write completes. Takes an optional timeout in seconds, after which will return nil. Returns nil, or raises an error if the write failed.Community Examples