0

I have a local node project running on localhost:3000 and it also has socket.io available for use. If I deploy the project to heroku and use

var socket = io.connect('http://herokuapss....'); 

and the cordova app to my phone it will work perfectly. I don't want to keep deploying to my phone, so I decided to use the localhost node project and an emulator. Therefore I change the socket to

var socket = io.connect('http://localhost:3000/');

But when I start the app on the emulator I see this in the console:

http://localhost:3000/socket.io/?EIO=3&transport=polling&t=LlvgDEL Failed to load resource: net::ERR_CONNECTION_REFUSED

How can I solve this?

Edit: I have also tried

http://127.0.0.1:3000

Server side socket:

let server = app.listen(port);
let io = require('socket.io').listen(server);
Bogdan Daniel
  • 2,689
  • 11
  • 43
  • 76
  • how do you load socket.io to your app? – mk12ok May 11 '17 at 23:10
  • it seems you have no server running on localhost.. and if you replace `io.connect('http://localhost:3000/')` with `io.connect()` ? – mk12ok May 11 '17 at 23:27
  • I do have. I'm looking at it. I m even browsing it. – Bogdan Daniel May 12 '17 at 00:04
  • And I do load it as it should, because it is actually running on heroku and cordova deployed on mobile. – Bogdan Daniel May 12 '17 at 00:04
  • and if you deploy cordova app on your mobile and connect to your local computer instead of heroku? – mk12ok May 12 '17 at 00:26
  • How can I connect to my local host from mobile and why would I want to do that? The point was to use the emulator. – Bogdan Daniel May 12 '17 at 00:29
  • you can connect with `var socket = io.connect();` to check if `localhost` on emulator is ok – mk12ok May 12 '17 at 00:31
  • you can try `10.0.2.2:3000` instead of `localhost` on emulator – mk12ok May 12 '17 at 00:38
  • My ip doesn't work, but the `10.0.2.2` does. Why is that? I found an answer here: http://stackoverflow.com/questions/9808560/why-do-we-use-10-0-2-2-to-connect-to-local-web-server-instead-of-using-computer. You can answer it so I can accept. – Bogdan Daniel May 12 '17 at 00:40
  • have a look here: [Set Up Android Emulator Networking](https://developer.android.com/studio/run/emulator-networking.html) – mk12ok May 12 '17 at 00:51

0 Answers0