Socket.io can't connect on mobile browser even with wifi on - javascript

to try socket.io, I coded a simple chat which works well on every pc. However, on mobile (I tried on my iphone 4S and an Ipad) even if the html is running well, it looks like the connect line let socket = io(); doesn't work, so nothing is working from socket.io. I saw online that it was working on wifi but it doesn't work either. I also saw that running the server on port 433 could help but socket io still doesn't connect(it works well for everyone who is on PC).
Any idea why and how to correct that ? I do want to target mobile browser for my app.
Here's my client code : [deleted]
EDIT : it does the same on android, while PC does an awesome job at running it.
EDIT2 : I just debbugged on mobile with android, it throws a "Uncaught SyntaxError: Unexpected identifier" on the "let socket = io();" line
Why ?

Going to need a lot more information than that to give a useful response.
A snippet of your socket io server call would suffice.
From what I can gather I believe that you must be running your socket server locally on your machine not using a web server. So I believe you will either need to open up the port you're attempting to connect to with your mobile device, or make sure you're targeting the correct internal IP address of the machine you are running the socket server from.

Related

net::ERR_NETWORK_CHANGED on Chrome on Https socket connection

I'm running a Server-sent Event (SSE) server over Ingress/Kubernetes/GoogleCloud and it works like a charm. I can run SSE clients over the web and they connect perfectly, start receiving events with no problem.
But there's one ugly bug I can't get it work right, on Chrome browsers after some time I get net::ERR_NETWORK_CHANGED error. No matter how many times I run it, I always get it after a few seconds/minutes.
If I run the same client over Firefox, nothing wrongs happens. If I run it using cURL over terminal, nothing wrong happens.
If I decide to run if over Chrome without HTTPS, it works! I'm only getting it when running it through HTTPS and on a Chrome browser.
Has anyone encountered this before? Seems like a ugly bug for me.
I'm having the same problem but it's sporadic.
From the Chromium project source code: OnNetworkChanged will be called when a change occurs to the host computer's hardware or software that affects the route network packets take to any network server. Some examples:
A network connection becoming available or going away. For example
plugging or unplugging an Ethernet cable, WiFi or cellular modem
connecting or disconnecting from a network, or a VPN tunnel being
established or taken down.
An active network connection's IP address changes.
A change to the local IP routing tables.
Hope it helps
For me using a mac system and chrome for a daily basis, I encounter this problem now and then and finally found it might be helpful to solve this problem by just turning off the virtual machines or dock containers whichever can adjust your network configuration.
Maybe not fit for your case but it could be a hint. I saw a lot of people having this kind of issue with chrome.

Error in creating a websocket connection within a hybrid app

I have an app that uses socket.io (1.4.5) to establish a websocket connection. The app is available via a web URL and also as a packaged Android app using Trigger.io.
The Android app is unable to connect to my websocket server. This is the error I receive
WebSocket connection to 'wss://myserver.com/socket.io/?user_id=xxx&session_token=xxx&EIO=3&transport=websocket' failed: Unspecified reason
The line it references in the socket.io client is within the doOpen() method.
this.ws = BrowserWebSocket ? new WebSocket(uri) : new WebSocket(uri, protocols, opts);
I haven't made any changes to the websocket server as far as I'm aware. And the website itself is running fine and able to connect to the websocket server.
I've inspected the Trigger.io Android app using Chrome Devtools and when I manually try to connect to my websocket server I get the same error. The following line of code does not work.
new WebSocket("wss://myserver.com/socket.io/?user_id=xxx&session_token=xxx&EIO=3&transport=websocket")
Running the same line of code in the Chrome browser works just fine.
Also, the error response seems too fast. It looks like the webview within the hybrid app isn't even trying to connect. The response is the same whether the websocket server is running or not. Typing in a nonsense URL gives the same error.
new WebSocket("wss://blahblah"); //gives the same error and response immediately
The Chrome version within the Trigger app is 55.0.2883.91.
EDIT : I tested the websocket connection on the mobile browser of the device running the app, just to make sure it's not a proxy / connection issue. And that worked fine.
The solution to this is to use the httpd module in Trigger.
Setting up the httpd server makes the app be served with a http://localhost URL instead of the contents: or file: protocol. With this in place, whatever Chrome CSP issue was blocking the connection is lifted.
Module docs : https://trigger.io/modules/httpd/current/

Cannot host WebSocket Server - error during handshake

I want to try a WebSockets and I found this artcile on the internet Using WebSocket in .NET
I am sure that I did every step properly, I enabled WebSockets in IIS, I wrote all clases which are mention in article, I register HTTP Handler in web.config etc.. but when I want to try it I still get exception:
WebSocket connection to 'ws://localhost/CodeProjectWeb/WSHandler.ashx' failed: Error during WebSocket handshake: Unexpected response code: 404
I know that 404 probably means that URL is wrong, but how can be wrong? Some additional info: I am running on windows 10, IIS 10.0 Express, .NET 4.6, Visual Studio 2013, I tried it on Google Chrome, Firefox (both last versions).
To be honest, this is not first tutorial which I tried. I already tried antoher 3-4 articles about WebSocket in .NET, also I tried use SignalR but still with the same results. I just dont know, I think that I am missing some important little thing..
If you need some more information just ask but I hope I write everything
I finally figure it out (probably). I have to turn off Windows Firewall to make it work. So if you have similar problem just be sure that your Firewall is turn off.

Does chrome debug tools "port forwarding" work on native apps as well as webview apps?

I'm using Chrome port forwarding on my Cordova-based hybrid app, and it works fine for AJAX calls made from HTML/Javascript. As expected, AJAX calls to http://localhost:8080 forward to my desktop where my development server is running Apache on port 80. See image below.
However, my app also makes an HTTP request in native code (I'm registering for GCM messages). As far as I can tell, the port forwarding does not work for that request.
I'm using standard Java (no special HTTP client classes or anything):
URLConnection yc = registration_url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
etc.
Does anyone know how Chrome port forwarding works? Is it a proxy at the OS level of the device, or somehow built into WebView? Has anyone been able to get this to work with native code?
FYI: I could convert my GCM registration to Javascript, but am hoping to avoid that work.
It looks like the Chrome port forwarding only works within WebView. For native code, I ran adb port forwarding and that worked.
adb forward tcp:8080 tcp:80
So on an app which uses both Javascript network calls and native network calls, I need to run both tools.
Any comments on how this works would be very helpful.

WebSocket: onMessage() only triggered at the end when server is closing connection

I have a weird error that I can not solve.
My implementation WebSocket works perfectly. The browser connects to the server, exchange their keys and the connection is fully established! The server starts sending messages to clients (visible in the network traffic).
But on my PC, all browsers (Chrome, Firefox, portable or not), the "onMessage ()" is correctly interpreted ... but only at the end when I turn off the server! In other words, if I put an alert () to each onMessage (), during exchange, I did absolutely nothing. But once I cut the server, I receive all alerts at once!
Yet on my MacBook everything works perfectly.
This ironic is it that behavior that affects all of my browsers on my PC. I run under Windows 7.
Thank you in advance ;)
I've finally found the issue !
If you have some troubles with Websockets, just disable the SSDP discover service on Windows.
net stop SSDPSRV
I ran into a similar issue recently. web server runs a separate SSDP discovery process to find uPnP devices on the network. When I had SSDP enabled, my websocket connection was always closed. Disabling SSDP solved it. But I haven't had a chance to investigate why.

Categories

Resources