Skip to content

Latest commit

 

History

History
99 lines (67 loc) · 1.68 KB

api-docs.md

File metadata and controls

99 lines (67 loc) · 1.68 KB
layout permalink
page
/api-docs/

net.TCPSocket

Provides raw TCP protocol connection socket.

constructor()

Create new socket object in the closed state.

const 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, but keep receiving new data.

socket.halfclose();

close()

Close the socket, stop transmitting and receiving new data.

socket.close();

ondata

Handler for received data events.

socket.ondata = function(buffer) {
  console.log(buffer);
};

Example

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

socket.onopen = function() {
  socket.send(new Uint8Array([1, 2, 3]));
};

socket.ondata = function(buf) {
};

socket.onend = function() {
};

socket.open('127.0.0.1', 8080);