socket.io not connecting to mobile browser

10.2k Views Asked by At

I wanna create a connection between my mobile Safari and nodejs + socket.io on my Macbook.

When i call localhost:8080 from my laptop, everything works fine. The console says that the client is connected and my little website is displayed.

When i call it over my mobile browser with 10.0.1.5:8080, the website is displayed as well, but my socket.io don't identify the mobile browser (iPhone) as client and nothing happens on the console board.

Does anybody where the problem is?

2

There are 2 best solutions below

0
On

WebSockets do not work over cellular network as they are not forwarded by the http proxy.

A possible workaround it to set the WebSocket server port to 443 (https) which forwards everything (as https is encrypted the proxy has to forward it in order to support https).

To see a real world example which solves this problem this way checkout nearby.

Remember this requires using two http servers:

  1. Serving you mobile application (on port 80)
  2. Serving the web sockets on (port 443)

Else you always have to use the specific ports in your urls which is mostly not preferred in production.

0
On

I found this post on SO, probably can help you out. why does my nodejs socket.io app not work on ios6

Localhost is local to the machine. You're IP should use a ip address or domain name:

something like: io.connect('192.168.1.110'); or io.connect('test.myapp.com');