1var Socket = new WebSocket('ws://' + window.location.hostname + ':81/'); // The '81' here is the Port where the WebSocket server will communicate with
2// The instance of the WebSocket() class (i.e. Socket here), must need to be globally defined
3
4Socket.send("pass your data here, and it'll be String"); // This method one can call locally
1var exampleSocket = new WebSocket("wss://www.example.com/socketserver", "protocolOne");
2
1// npm install --save ws
2const WebSocket = require('ws');
3
4const ws = new WebSocket('ws://www.host.com/path');
5
6ws.on('open', function open() {
7 ws.send('something');
8});
9
10ws.on('message', function incoming(data) {
11 console.log(data);
12});