Skip to content

Instantly share code, notes, and snippets.

@RaccoonDev
Last active October 31, 2017 09:39
Show Gist options
  • Save RaccoonDev/2b694210746656d8771029e67f1d08d1 to your computer and use it in GitHub Desktop.
Save RaccoonDev/2b694210746656d8771029e67f1d08d1 to your computer and use it in GitHub Desktop.
Websockets testing
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
'use strict';
var msg = {
name: 'channel add',
data: {
name: 'Hardware support'
}
};
var ws = new WebSocket('ws://localhost:4000');
ws.onopen = function () {
ws.send(JSON.stringify(msg));
};
ws.onmessage = function (e) {
console.log(JSON.parse(e.data));
};
</script>
<script id="jsbin-source-javascript" type="text/javascript">let msg = {
name: 'channel add',
data: {
name: 'Hardware support'
}
}
let ws = new WebSocket('ws://localhost:4000');
ws.onopen = () => {
ws.send(JSON.stringify(msg));
}
ws.onmessage = (e) => {
console.log(JSON.parse(e.data));
}</script></body>
</html>
'use strict';
var msg = {
name: 'channel add',
data: {
name: 'Hardware support'
}
};
var ws = new WebSocket('ws://localhost:4000');
ws.onopen = function () {
ws.send(JSON.stringify(msg));
};
ws.onmessage = function (e) {
console.log(JSON.parse(e.data));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment