IoT.js provides asynchronous networking through Net module.
You can use this module with require('net')
and create both servers and clients.
options: Object
connectionListener: Function(connection: net.Socket)
Creates a TCP server according to options
.
connectionListener
is automatically registered as connection
event listener.
options: Object
port: Number
host: String
, Default:localhost
connectListner: Function()
Creates a net.Socket
and connects to the supplied host.
It is equivalent to new net.Socket()
followed by socket.connect()
.
You can create net.Server
instance with net.createServer()
.
port: Number
host: String
backlog: Number
listenListener: Function()
Starts listening and accepting connections on specified port and host.
closeListener: Function()
Stops listening new arriving connection.
Server socket will finally close when all existing connections are closed, then emit 'close' event.
closeListener
is registered as close
event listener.
Emitted when server has been started listening.
socket: net.Socket
Emitted when new connection is established.
Emitted when server closed.
Note that this event will be emitted after all existing connections are closed.
Emitted when an error occurs.
options: Object
Creates a new socket object.
options
is an object specifying following information:
allowHalfOpen: Boolean
options: Object
port: Number
- 'host: String
, Default:
'localhost'`
Opens the connection with supplied port and host.
options
is an object specifying following information:
port: Number
- port connect to (required)host: String
- host connect to (optional, default:'127.0.0.1'
)
connectionListner
is automatically registered as connect
event listener which will be emitted when the connection is established.
data: String | Buffer
callback: Funciton()
Sends data
on the socket.
callback
function will be called after given data is flushed through the connection.
data: String | Buffer
callback: Funciton()
Half-closes the socket.
If data
is given it is equivalent to socket.write(data)
followed by socket.end()
.
data: String | Buffer
Destroys the socket.
Pauses reading data.
Resumes reading data after a call to pause()
.
timeout: Number
callback: Function()
Sets timeout for the socket.
If the socket is inactive for timeout
milliseconds, 'timeout'
event will emit.
callback
is registered as timeout
event listener.
enable: Boolean
initilalDelay: Number
, Default:0
Enables or disables keep-alive functionality.
err: Error | Null
address: String
family: String | Null
Emitted after resolving hostname.
Emitted after connection is established.
- data: Buffer | String
Emitted when data is received from the connection.
Emitted when the write buffer becomes empty.
Emitted when FIN packet received.
Emitted when the connection remains idle for specified timeout.
Emitted when the socket closed.
Emitted when an error occurs.