var ws = new WebSocket('ws://localhost/socket.io/?EIO=3&transport=websocket');
ws.send('42' + JSON.stringify(['hello', 'there']));
// ws.onmessage will get a MessageEvent object with the data property being encoded in the similar way.
var socket = io('http://localhost');
socket.emit('hello', 'there');
const socket = new WebSocket("ws://localhost:3000");
socket.addEventListener("open", () => {
// send a message to the server
socket.send(JSON.stringify({
type: "hello from client",
content: [ 3, "4" ]
}));
});
// receive a message from the server
socket.addEventListener("message", ({ data }) => {
const packet = JSON.parse(data);
switch (packet.type) {
case "hello from server":
// ...
break;
}
});