| layout | permalink |
|---|---|
page |
/api-docs/ |
Provides raw TCP protocol connection socket.
Create new socket object in the closed state.
const 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, but keep receiving new data.
socket.halfclose();Close the socket, stop transmitting and receiving new data.
socket.close();Handler for received data events.
socket.ondata = function(buffer) {
console.log(buffer);
};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);