DataSocket object

DataSocket’s are used to duplex data transfer using TCP/IP sockets between two Sciter processes running either on the same machine ("localhost" address) or over the wire inside local network. DataSocket supports server listening sockets (DataSocket.listen() ) and client sockets (DataSocket.connect()) .

DataSocket sends/receive data in serialized binary form – you send data by socket.send(data) and receive them by socket.on("receive", function(data) {}) on other end. No additional stringify/parsing is required.


boolean, socket state, true – socket is alive.
– string, address of the remote machine.



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

Constructs client DataSocket. Returns new socket in connecting state.


( 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.


( event: string, callback: function ) : this

Subscribes the callback to one of socket events:

  • "connect" -> function(), socket just connected to the host;
  • "data" -> function(data:any), the data has been received;  
  • "sent" -> function(), data were sent in full;
  • "error" -> function(err: Error), error occured, error object passed to the function;
  • "close" -> function(), socket was closed;

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


( event: string, callback: function ) : this

Same as on() but subscribes the callback for one time execution ( handler will be auto removed after first call )


( 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.


( data: any )

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


( )

Closes the socket.