The net module provides you with an asynchronous network wrapper. It contains methods for creating both servers and clients (called streams).

Static methods

staticconnect(options:EitherType<NetConnectOptionsTcp, NetConnectOptionsUnix>, ?connectListener:() ‑> Void):Socket

staticconnect(path:String, ?connectListener:() ‑> Void):Socket

staticconnect(port:Int, ?connectListener:() ‑> Void):Socket

staticconnect(port:Int, host:String, ?connectListener:() ‑> Void):Socket

A factory function, which returns a new Socket and automatically connects with the supplied options.

The options are passed to both the Socket constructor and the socket.connect method.

The connectListener parameter will be added as a listener for the connect event once.

If port is provided, creates a TCP connection to port on host. If host is omitted, 'localhost' will be assumed.

If path is provided, creates unix socket connection to path.

Otherwise options argument should be provided.

staticcreateConnection(options:EitherType<NetConnectOptionsTcp, NetConnectOptionsUnix>, ?connectListener:() ‑> Void):Socket

staticcreateConnection(path:String, ?connectListener:() ‑> Void):Socket

staticcreateConnection(port:Int, ?connectListener:() ‑> Void):Socket

staticcreateConnection(port:Int, host:String, ?connectListener:() ‑> Void):Socket

Same as connect.

staticcreateServer(?connectionListener:Socket ‑> Void):Server

staticcreateServer(options:NetCreateServerOptions, ?connectionListener:Socket ‑> Void):Server

Creates a new TCP server.

The connectionListener argument is automatically set as a listener for the 'connection' event.

staticisIP(input:String):NetIsIPResult

Tests if input is an IP address. Returns 0 for invalid strings, returns 4 for IP version 4 addresses, and returns 6 for IP version 6 addresses.

staticisIPv4(input:String):Bool

Returns true if input is a version 4 IP address, otherwise returns false.

staticisIPv6(input:String):Bool

Returns true if input is a version 6 IP address, otherwise returns false.