Net.Socket object

Sockets are used for duplex raw data transfer using either named pipes (Windows) or TCP/IP sockets between two Sciter processes running either on the same machine ("localhost" address) or over the wire. Socket supports server listening sockets (Socket.listen() ) and client sockets (Socket.connect()) .

Socket sends/receive raw data - strings or bytes. You send data by socket.send(data) and receive them by socket.on("receive", function(data) {}) on other end.

Properties

Methods

connect

( port: integer [, domain: string] ) : DataSocket

Constructs client DataSocket. Returns new socket in connecting state.

listen

( acceptor: function, port: integer [, domain: string] ) : DataSocket

Constructs server DataSocket. Returns new socket in listening state.

The acceptor function is being called on each new connection request to the server. It has following signature:

function acceptor( connectionSocket: DataSocket ) : true | false

where connectionSocket is another instance of DataSocket used for communication with remote peer.

You MUST return true from the acceptor in order to accept and use the connection.

on

( event: string, callback: function ) : this

Subscribes the callback to one of socket events:

The event name may contain ".namespace" part that can be used in .off() call.

off

( event: string | callback: function ) : this

Unsubscribe callback either by its name or by its function reference.

Event name may contain only namespace part, so this: socket.off(".namespace") will unsubscribe all handlers that were set with that namespace.

send

( data: any )

The method sends data to the peer. The data can be any serializeable data type (object, number, string, array, etc.).

close

( )

Closes the socket.