I'm building a test chat app client with node.js, socket.io and cordova.
Executing cordova run browser
browser opens to http://localhost:8000.
In index.js of my cordova chat client app i got code to connect to my server side socket.io:
var socket = io.connect('https://node-socket.io-address/');
socket.on('connect', function() {.............
Problem is that i receive this kind of error:
So as you can see there is a port (8000) added to the link. This problem is not occuring when I run app on android device (cordova run android).
Why cordova is adding port to external links ? Can disable port adding to external links on cordova run browser ?
It's not cordova adding port to your URL, it's socket.io client, here:
this.port = opts.port || (global.location && location.port ?
location.port :
(this.secure ? 443 : 80));
When port is not defined, it defaults to port of application. That is probably a bug in socket.io, since it makes sense only if webpage and server are hosted from same node. Your problem originates from the fact, that it is cordova which serves your application (on localhost:8000) and socket.io assumes that websocket will be on same port.
To avoid it, you should add port to URL or the opt
ions object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With