socketio event code example
Example 1: socket.io client send data node js server
var socket = io.connect('http://localhost');
socket.emit('my other event', { my: 'data' });
//server side
io.sockets.on('connection', function (socket) {
socket.on('my other event', function (data) {
console.log(data);
});
});
//sending data from the user via a socket.io
socket.on("test", function (data) {
data.forEach(obj => {
console.log("Yer : " + obj.yer + ", Lat : " + obj.lat + ", Long : " + obj.lng);
})
});
Example 2: socket.io doc
const socket = new WebSocket('ws://localhost:3000');socket.onopen(() => { socket.send('Hello!');});socket.onmessage(data => { console.log(data);});