1const socket = io('ws://localhost:3000');
2socket.on('connect', () => {
3 // either with send()
4 socket.send('Hello!');
5 // or with emit() and custom event names
6 socket.emit('salutations', 'Hello!', { 'mr': 'john' }, Uint8Array.from([1, 2, 3, 4]));});
7// handle the event sent with socket.send()
8socket.on('message', data => {
9 console.log(data);
10});
11// handle the event sent with socket.emit()
12socket.on('greetings', (elem1, elem2, elem3) => {
13 console.log(elem1, elem2, elem3);
14});