Skip to content
Tres Finocchiaro edited this page Apr 26, 2021 · 2 revisions

Compatibility

  • ✅ 2.1 | ⛔ 2.0 | ⛔ 1.9 | ...

Since 2.1.3

Summary

Establish a two-way TCP socket connection using the qz.socket API.

⚠️ Socket API is experimental; API subject to change.

Opening the socket

qz.socket.open('192.168.1.1', '80').then(() => {
   console.log("Socket opened");
}).catch(err => {
   console.error("An exception occurred opening the socket", err);
});

Sending data

qz.socket.sendData('192.168.1.1', '80', "some data!").catch(err => {
   console.error("An exception occurred sending data to the socket", err);
});

Processing Data

qz.socket.setSocketCallbacks(evt => {
   if (evt.type !== 'ERROR') {
      console.log('Socket', evt.host, evt.port, 'received response', evt.response);
   } else {
      console.error(evt.exception);
   }
});

Closing the socket

qz.socket.close('192.168.1.1', '80').then(() => {
   console.log("Socket closed");
}).catch(err => {
   console.error("An exception occurred closing the socket", err);
});