-
Notifications
You must be signed in to change notification settings - Fork 126
API docs
runtime object is the main entry point to the system API. It's exported from the runtimejs package:
var runtime = require('runtimejs');Provides raw TCP protocol connection socket.
Create new socket object in the closed state.
var socket = new runtime.net.TCPSocket();Open socket and connect to TCP server using ip address and port.
| Argument | Type | Description |
|---|---|---|
| ip | string | Server IP address to connect to. |
| port | number | TCP server port. |
socket.open('127.0.0.1', 8080);Push data buffer into socket transmit queue. This does not copy data, buffer will be sent directly to network interface, data modifications made after send() call may affect transmitted data.
| Argument | Type | Description |
|---|---|---|
| buffer | Uint8Array | Buffer to send. |
| return | bool | Hint to the caller that transmit queue is full. |
socket.send(new Uint8Array([1, 2, 3]));Send stream ended notification (FIN packet), but keep receiving new data.
socket.halfclose();Close the socket, stop transmitting and receiving new data.
socket.close();Handler for socket opened (connection) event.
socket.onopen = function() {
console.log('connected');
};
socket.open('127.0.0.1', 8080);Handler for received data events.
socket.ondata = function(buffer) {
console.log('new data', buffer);
};Handler for halfclose() event from the other end (received FIN packet).
socket.onend = function() {
console.log('received all data');
};Handler for socket closed event.
socket.onclose = function() {
console.log('socket closed');
};