Callback format: The first argument of the callback is reserved for an error object. If an error occurred, it will be returned by the first err argument. The second argument of the callback is reserved for any successful response data. If no error occurred, err will be set to null and any successful data will be returned in the second argument.
Create new transport layer obj via calling Transport with IP
const transport = new Transport('192.168.1.1');
transport.tryConnect((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', (err) => {
if(err) {
// AHHH error
return;
}
console.log('message sent properly');
});
You can listen to message from the server through .listen, this is a callback with the message.
transport.listen((err, message) => {
console.log('Message from server', message);
});
transport.onClose((err) => {
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()