Skip to content

Instantly share code, notes, and snippets.

@miketamis
Forked from fllfl/document.md
Last active February 6, 2017 22:24
Show Gist options
  • Save miketamis/99a7fdbfd04c391ae2a13f49710bd8b6 to your computer and use it in GitHub Desktop.
Save miketamis/99a7fdbfd04c391ae2a13f49710bd8b6 to your computer and use it in GitHub Desktop.

Create new transport layer obj via calling Transport with IP

const transport = new Transport('192.168.1.1');
transport.tryConnect().then(err, res) {
  if(err) {
    console.log(err);
  } else {
    console.log('we are connected');
    //do something
  }
});

To write a message over the socket use write, this will return a promise. The promise will only resolve if an ack is recieved.

transport.write('Hello how are you doing').then(() => {
  console.log('message sent properly');
});

You can listen to message from the server through .listen, this is a callback with the message.

transport.listen((message) => {
  console.log('Message from server', message);
});

To end and writeOut the writes that are buffered.

transport.end()

To DESRTROY aaaaaahh don't don't hurt me

transport.destory()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment