0

I am running a node.js server on port 3000 and it works fine when I aceess it on localhost:3000 on my local system. I am also printing the mouse co-ordinates on to the console using

socket.broadcast.emit('mouse',data);

But I wanted to make this work on a remote system like my mobile. So when I looked up I found out that I should change my server code from

.listen(3000);

to

.listen(3000,'0.0.0.0');

and using my local ip address 192.168.x.x:3000 I was able to get the client on my mobile. But I am not able to receive the mouse co-ordinates on the console when I access the client on my mobile. I have used socket.io to create a websocket. Both my mobile and laptop are connected to the same wi-fi. I tried disabling the firewall also.

My server code:

var server = app.listen(3000,'0.0.0.0');
app.use(express.static('public'));
var socket = require('socket.io');
var io=socket(server);
io.sockets.on('connection',newConnection);
function newConnection(socket)
{
 console.log('new connection:' + socket.id );
 socket.on('mouse',mouseMsg);
 function mouseMsg(data){
 socket.broadcast.emit('mouse',data);
 console.log(data);
}
}
  • I am not sure if socket recognizes touch as mouse. Chrome for Android surely doesn't. Try 'touchmove' instead. – Aniket Chowdhury Mar 28 '19 at 19:27
  • Found this too https://stackoverflow.com/questions/34212762/touchmove-data-is-not-transmitted-constantly-to-node-js – Aniket Chowdhury Mar 28 '19 at 19:31
  • Thanks for the reply. But I am not able to receive data to my local node server from another laptop also. I am not able to connect to the server from another laptop. Not only mobile, even laptop its not working. So I think touchmove is an issue. The console on my client shows GET http://localhost:8080/socket.io/socket.io.js net::ERR_CONNECTION_REFUSED this error. Please let me know what to do. – Pranathi B S Mar 29 '19 at 10:54

1 Answers1

0

Solved this problem by entering the IP address of the system 192.168.x.x in both my server and client program.