javascript websocket code example
Example 1: javascript websocket example code
var Socket = new WebSocket('ws://' + window.location.hostname + ':81/');
Socket.send("pass your data here, and it'll be String");
Example 2: js connect to websocket
var exampleSocket = new WebSocket("wss://www.example.com/socketserver", "protocolOne");
Example 3: javascript websocket
const WebSocket = require('ws');
const ws = new WebSocket('ws://www.host.com/path');
ws.on('open', function open() {
ws.send('something');
});
ws.on('message', function incoming(data) {
console.log(data);
});