Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.

API docs

Serge edited this page Jul 19, 2015 · 16 revisions

API docs

runtime object is the main entry point to the system API. It's exported from the runtimejs package:

var runtime = require('runtimejs');

net.TCPSocket

Provides raw TCP protocol connection socket.

constructor()

Create new socket object in the closed state.

var socket = new runtime.net.TCPSocket();

open(string ip, number port)

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);

send(Uint8Array buffer)

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]));

halfclose()

Send stream ended notification (FIN packet), but keep receiving new data.

socket.halfclose();

close()

Close the socket, stop transmitting and receiving new data.

socket.close();

onopen = function()

Handler for socket opened (connection) event.

socket.onopen = function() {
  console.log('connected');
};
socket.open('127.0.0.1', 8080);

ondata = function(buffer)

Handler for received data events.

socket.ondata = function(buffer) {
  console.log('new data', buffer);
};

onend = function()

Handler for halfclose() event from the other end (received FIN packet).

socket.onend = function() {
  console.log('received all data');
};

onclose = function()

Handler for socket closed event.

socket.onclose = function() {
  console.log('socket closed');
};
Clone this wiki locally