Websockets on localhost wihout SSL - javascript

This line:
var socket = new WebSocket(this.getUrl());
Causes error:
WebSocket connection to 'ws://127.0.0.1:6437/v6.json' failed: Error during WebSocket handshake: Unexpected response code: 400
I'm guessing I could get around it by using SSL but as I’m just playing around locally with MAMP it would be nice not to have to set this up. I get the same from Chrome, Firefox and Safari. The context is that I’m playing with a Leap Motion controller and everything works fine as long as it’s running remotely with SSL.
Do I really need SSL for all local development using web sockets or am I missing something?

You don't need SSL/TLS to use WebSockets unless you are connecting from a page that is also using SSL/TLS -- I'm looking t such a page right now and it works fine. Do the sample apps (Sample.html and JSONViewer.html) in the Leap Motion SDK work for you?

Related

WebSocket connectivity issues

I have one websocket server running in java application written using https://github.com/TooTallNate/Java-WebSocket and trying to connect to it
from browser. The browser is sending request to connect every second till the websocket server initializes. Chrome connects blazingly fast as soon the websocket is initialized. Firefox takes atleast 10-15 seconds to connect. Is there any way firefox to connect as chrome connects. I have checked the headers in both browser "keep-alive" header is sent in firefox and chrome doesnot send. Will it be affecting the connection ?
First test with this..
http://demos.kaazing.com/echo/
so that you will be able to know which side is the problem.
Issue resolved. It was becuase i was using the old version which was created in 2013. The spec and implementation changed a lot. Thanks #Nitish Dhapodkar i used that website to check connectivity.

WebSocket network error: OSStatus Error -9807: Invalid certificate chain

I'm getting following error while connecting to websocket's in safari, In remaining browsers it is working fine
Error:
WebSocket network error: OSStatus Error -9807: Invalid certificate chain
Code:
var websocket = new WebSocket("wss://localhost:44300/websocketHome", "Room_123")
The workaround is to enable NSURLSession Websocket in Settings > Safari > Advanced > Experimental Features > NSURLSession Websocket. Should work on iOS 13.4.1+.
Note this may not be suitable for production environments.
So I'm going to start this answer with a caveat: I'm not an expert in WebSockets, Browsers, Safari, or URLs. The reason I mention this is that I don't know why this solution works and I don't know why Safari behaves in the way that it does.
I spent a good couple of hours figuring out why my site wasn't working in Safari, but was working in every other browser. And it pisses me off, because I don't have time for this rubbish.
Essentially what you need to do is replace this:
var websocket = new WebSocket("wss://localhost:44300/websocketHome", "Room_123")
with this:
var websocket = new WebSocket("ws://localhost:44300/websocketHome", "Room_123")
But don't kick yourself yet, because you weren't imagining it when it worked in Chrome and Firefox. Safari seems to be the only browser enforcing the protocol part of the URL, i.e. "ws" instead of "wss" for localhost connections.
Basically I don't have time to research if Safari is following the standard properly or not, but it doesn't matter, because I'm going to chalk this up as yet another example of Safari(the Internet Explorer of 2017) unnecessarily breaking from the herd to make life difficult for web developers.
If Apple want to enforce standards that the other browsers don't, they're welcome to do that, but they at least need to print useful errors, WebSocket network error: OSStatus Error -9807: Invalid certificate chain isn't good enough.
Edit
This will be obvious to most people, but for those who aren't professional developers, make sure you don't deploy this change to production. You want to be using the wss protocol for production, and that should work fine on Safari if you've got your certificates set up properly.
We ran into this error, secure WebSockets weren't working in newer versions of OSX under Safari and Chrome, with a LetsEncrypt certificate. The fix for us was to replace references to "cert.pem" with "fullchain.pem", as described in this link
https://community.letsencrypt.org/t/issues-on-mac-with-wss-osstatus-error-9807-invalid-certificate-chain/160930

TLS WebSocket Server working with firefox client but not with chrome client

I have a server, created in c++ that accepts TCP connections. We have a few clients that can connect on it (iOS, Android, web). I'm trying to add support for TLS now, but I can't seem to get it right. The TLS connection works when using Firefox, but not when using Chrome.
The code to start the connection is pretty simple:
var socket = new WebSocket(host);
The server side is a bit more complex, it can be found here
I inspected what happens with Wireshark. The results for Firefox can be seen here and the results for Chrome can be found here.
What is going wrong here? Does Chrome require something special before the TLS connection can be established?
I have solved my problem. It turns out that there was nothing wrong with my code, but that Google Chrome has a strict poly regarding certificates. I was testing with an untrusted self-signed certificate. When I tested with the company trusted certificate everything worked.

Websockets no longer work for me at all

I've been programming alot for the Leap Motion lately, writing javascript web apps for it. The Leap sends data through a websocket that you can receive in the browser. I've been using it no problem for months. All of a sudden I can't get data from it through the websocket. I uninstalled and re-installed the software, tried with a different device, tried different versions of their software, restart the computer many times and nothing helps. All the software works fine for everyone else I know with a Leap and it works fine on my other computer. It happens in firefox, chrome, and nodewebkit. It happens for stuff hosted on my server, my desktop, and other peoples servers. I'm on win7.
Now I am thinking that there is something messing with the websocket connection that isn't in their software, some setting or problem on my machine. I've tried using websocket demos I googled for and they don't seem to work either.
I went to http://websocketstest.com/ and I get disconnected on port 80, 443, and 8080, but it works on 443 with SSL.
What could it be?
This ended up being some anti virus software I installed blocking it.

Node.js/Socket.io not returning results in IE, using a secure connection

I have successfully implemented socket.io, node.js and express to server realtime json data to all browsers except IE (testing on 9) using a secure connection. This worked fine everywhere until I moved it behind https. From the server console output, it shows that an event is received when called from IE:
xhr-polling received data packet 5:::{"name":"lookup_place","args":
[{"place":"Berlin"}]}
However, no response is given and the next 4 lines shown in the console are:
clearing poll timeout
xhr-polling writing 8::
set close timeout for client 27081179790885432
xhr-polling closed due to exceeded duration
When the same is done from FF or Chrome, the line "xhr-polling writing 8::" is appended with the correct response, for example:
xhr-polling writing 5:::{"name":"place_results","args":[{"a":
[{"identifier":"52156","value":"Monschau, 52156"},
{"identifier":"67590","value":"Monsheim, 67590"},
{"identifier":"04617","value":"Monstab, 04617"}]}]}
I am using node.js version 0.4.10, socket.io version 0.7.7 and express version 2.4.3. The same scripts worked perfectly fine in IE 7-9 without an https/ssl/secure connection.
Any help would be greatly appreciated in discovering why no response is delivered in IE but works fine in all others.
Might be a bug. I would advice you to fill an issue at Socket.io's github issue page. Then the authors will also receive an email and probably respond pretty fast.

Categories