Endpoint HandShake exception - javascript

I am getting
WebSocket connection to 'ws://localhost:8080/EchoChamber/echo' failed: Error during WebSocket handshake: Unexpected response code: 302
I started exact same project, as here: link.
I am using Tomcat 6. How fix this?

WebSocket clients expect that 101 Switching Protocols is returned from a server, but your endpoint returns 302 Found. Check the settings of your server.

Related

How to connect SSL websocket with mqtt?

I created a self signed certificate and I've been working on the mqtt websockets over SSL/TSL, however I'm unsure exactly where I made an error. On my terminal websocket is open and sends out CONNACK/SUBSCRIBE/PUBLISH etc...
However when I opened up my chrome console log, I got an error saying that
"websocket connection to 'wss:.//hostname:9001/mqtt' failed: Error in connection establishment: net: ERR_CERT_AUTHORITY_INVALID
My time is synchronised correctly, and I'm either thinking my certificate has an error or chrome doesn't accept it but if my certificate error, wouldn't it have given an error when I first tried it on regular mosquitto_sub?
Any tips?
Thank you

Coldfusion websocket cant create a websocket handshake while changing ws to wss protocol

Coldfusion websocket (using cfwebsocket with secure attribute true) cant create a websocket handshake, I am getting a connection refused error. To make websocket secure I followed these steps but I am getting
Error in connection establishment: net::ERR_CONNECTION_REFUSED in network WS tab
Administrator. Administrator console > Server Setting > WebSocket: Enabled SSL Port
Added secure attribute true for cfwebsocket tag

NodeJS socket.io throws error Connection closed before receiving a handshake response

I am using WAMP offline server and I installed NodeJS for my chat application. The chat application works fine but I receive this error in my console
WebSocket connection to 'ws://localhost:8000/socket.io/1/websocket/1300942723267398434' failed: Connection closed before receiving a handshake response
Even though the application works fine, but I don't want to see that error and I believe if I upload my application to a live server, it won't work perfectly because of this error.
I have tried many solutions from SO but it didn't work for me:
Socket.io - failed: Connection closed before receiving a handshake response
WebSocket connection to 'ws://localhost:3000/' failed: Connection closed before receiving a handshake response
Socket.io: Connection closed before receiving a handshake response
Below is my back end code
var io = require('socket.io').listen(8000),
dns = require('dns'),
express = require('express'),
mysql = require('mysql');
On the front end:
socket = io.connect('http://localhost:8000');
I have found the solution... The error came as a result of unsecured connection http after creating a secured connection to the server, the application work fine

Flask-SocketIO not connecting to WebSocket after deploying to Heroku

I am trying to create a real-time chatroom application using Flask-SocketIO. The app seems to work as intended when running on my local machine, however after deploying the app to Heroku the websocket won't connect and I get two errors:
WebSocket connection to 'wss://cs50flack.herokuapp.com/socket.io/?
EIO=3&transport=websocket&sid=8f8e233608794661a113fadc5418c27f' failed:
Error during WebSocket handshake: Unexpected response code: 400
and:
GET https://cs50flack.herokuapp.com/socket.io/?
EIO=3&transport=polling&t=1546556762105-
66&sid=b17b8d48610842fca97cbac3e030f3bd 400 (BAD REQUEST)
code: https://github.com/r0ss26/Flack
URL: https://cs50flack.herokuapp.com/

Websocket returns status 200 instead of 101 (flask socket.io)

I've done quite a bit of reading around to try and solve this issue but I'm still stuck. My problem is with trying to get the websocket handshake to complete using socket.io client side and flask_socket.io server side.
I can run the flask development server on my local machine using:
app = Flask(__name__)
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
socketio = SocketIO(app)
socketio.run(app)
...
and if I point chrome to localhost:5000 and press the button which I have linked to opening a websocket it works fine and chrome network tab shows status 101.
However on uploading the code to a remote machine and again using flask's development server but changing the port to 80,
socketio.run(app,host='0.0.0.0',port=80)
the websocket handshake stops working and gives status 200 instead.
WebSocket connection to 'ws://example.com/socket.io/?EIO=3&transport=websocket&sid=cfb1949b243b42578fe422782a0db359' failed: Error during WebSocket handshake: Unexpected response code: 200
All websocket messages are now sent over xhr polling instead of inside the websocket frame.
I've followed all of the guides I can find on google relating to this but with no success. I was previously using nginx and gunicorn and followed the advice to change the nginx conf to allow upgrade to websockets but that didn't solve the problem. So I simplified to using the flask development server but I still haven't been able to get a successful handshake.
I found a solution after finding a similar problem posted here https://nolanlawson.com/2013/05/31/web-sockets-with-socket-io-node-js-and-nginx-port-80-considered-harmful/#comment-85425.
It turns out many public wifi networks block websockets when they are running on port 80. However often ports 443 and 8080 are not blocked. You can find out which ports are blocked from this website: http://websocketstest.com/. I just moved the address of my websocket from example.com to example.com:8080.
I ran into a similar problem but due to a different reason. When using flask-socketio you have to install gevent-websocket or else it's going to use long-polling and you'll see a lot of 200 responses. Thus, my solution to that problem was just.
pip install gevent-websocket

Categories