1var socket = io.connect('http://localhost');
2socket.emit('my other event', { my: 'data' });
3//server side
4io.sockets.on('connection', function (socket) {
5 socket.on('my other event', function (data) {
6 console.log(data);
7 });
8});
9//sending data from the user via a socket.io
10socket.on("test", function (data) {
11 data.forEach(obj => {
12 console.log("Yer : " + obj.yer + ", Lat : " + obj.lat + ", Long : " + obj.lng);
13 })
14});
1<script src="/socket.io/socket.io.js"></script>
2<script>
3 const socket = io();
4</script>
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});