Skip to content

Instantly share code, notes, and snippets.

@Krknv
Created March 19, 2019 12:17
Show Gist options
  • Save Krknv/1fdd61da27e17aff64f6fe3ff929356a to your computer and use it in GitHub Desktop.
Save Krknv/1fdd61da27e17aff64f6fe3ff929356a to your computer and use it in GitHub Desktop.
var url = 'http://sample.com'
var ws = new WebSocket(url);
var msg = "hi, this is simple message.";
ws.onopen = function(evt) {
ws.send(msg);
};
ws.onmessage = function(evt) {
// handle this message
console.log(evt.data);
};
ws.onclose = function(evt) {
// this channel is closed
};
ws.onerror = function(evt) {
// handle this error
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment