Answer the question
In order to leave comments, you need to log in
How to send data from socket.io client?
Hello. I can not understand why the data from the client is not sent.
Server:
io.sockets.on('connection', function (client) {
client.on('messageClient', function (data) {
console.log(data.posX);
});
client.emit('messageServer', function (data) {
console.log(data);
});
});
var socket = io.connect('http://46.101.151.182:3000');
var sid = Math.round('');
socket.on('connect', function () {
console.log('Подключен!');
});
var ax, ay, acelX;
window.ondevicemotion = function(e) {
ax = e.accelerationIncludingGravity.x;
ay = e.accelerationIncludingGravity.y;
document.getElementById('info').innerHTML = ax+', '+ay;
}
socket.on('messageServer',function(data) {
console.log(data);
});
socket.emit('messageClient',{posX:ax});
Answer the question
In order to leave comments, you need to log in
When the page loads, it shows undefined, and that's it. Further data is not received
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question