Skip to content

Instantly share code, notes, and snippets.

@fllfl
Forked from miketamis/document.md
Last active February 3, 2017 04:14
Show Gist options
  • Save fllfl/1c1445431b3f8b254e5edcdfe1624f16 to your computer and use it in GitHub Desktop.
Save fllfl/1c1445431b3f8b254e5edcdfe1624f16 to your computer and use it in GitHub Desktop.

Create new transport layer obj via calling Transport with IP

const transport = 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 disconnect do disconnect :D

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