Skip to content

Instantly share code, notes, and snippets.

@fllfl
Forked from miketamis/document.md
Last active February 8, 2017 22:07
Show Gist options
  • Save fllfl/965e94ef323e85e77357a2bbc11b6c63 to your computer and use it in GitHub Desktop.
Save fllfl/965e94ef323e85e77357a2bbc11b6c63 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);
});
transport.onClose(() => {
  dosomething();
  leteveryoneknow to stop send shit;
  try to reconnect;
  dispatch(apiActions.onClose());
)
});

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