DataSocket's are used to duplex 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. 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.
( name: string [, port: integer] ) : DataSocket
Constructs client DataSocket. Returns new socket in connecting state. If port is provided then name is treated as a domain name or address and connection is made over TCP/IP. Otherwise named pipe name (or local domain socket) is assumed.
( acceptor: function, name: string [, port: integer] ) : DataSocket
Constructs server DataSocket. Returns new socket in listening state. If port is provided then name is treated as a domain name or address and connection is made over TCP/IP.
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:
function()
, socket just connected to the host;function(data:any)
, the data has been received; function()
, previous send()
operation completed;function(err: Error)
, error occured, error object passed to the function;function()
, socket was closed;The event name may contain ".namespace" part that can be used in .off() 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 method sends data to the peer. The data can be any serializeable data type (object, number, string, array, etc.).
( )
Closes the socket.