How to configure websocket? - javascript

On the local server, these settings work
CHAT_WS_SERVER_HOST = '0.0.0.0'
CHAT_WS_SERVER_PORT = 3000
CHAT_WS_SERVER_PROTOCOL = 'ws'
And the chat is working fine, but on Heroku there is an error(Chrome):
WebSocket connection to 'ws://0.0.0.0:41540/jgvnf53ky1m1lxt1vrka9lcnfilwhkrv/Pechkin' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
On Heroku I use such settings:
CHAT_WS_SERVER_HOST = '0.0.0.0'
CHAT_WS_SERVER_PORT = os.environ['PORT'];
CHAT_WS_SERVER_PROTOCOL = 'ws'
Python code
websocket = new WebSocket(base_ws_server_path + '{{ request.session.session_key }}/' + opponent_username);
JS code on client
websocket = new WebSocket(base_ws_server_path + 'jgvnf53ky1m1lxt1vrka9lcnfilwhkrv/' + opponent_username);
Fihish
ws://0.0.0.0:41540/jgvnf53ky1m1lxt1vrka9lcnfilwhkrv/Pechkin
I read that this is a problem because of the certificate (wss \ https), but I don't use him now... or with the wrong IP
Upd_1

The IP address 0.0.0.0 refers to the local server. When your browser connects to that address, it will reach the computer where the browser is running (e.g. your laptop). Since you want it to connect to your Heroku app, you need to replace the value 0.0.0.0 with the hostname for your Heroku app, e.g. your-app-name.herokuapp.com. This way, the browser will connect over the internet to your Heroku app instead.
The URL in the browser should look like ws://your-app-name.herokuapp.com:...

Related

WebSocket connection to '...' failed: Invalid frame header

I use express and socket.io
My node server is running on 127.0.0.1:3000
and i have connected it
var socket = io.connect('http://127.0.0.1:3000', {query: 'id=' + user.id});
There is a warning in my browser console.
WebSocket connection to 'ws://127.0.0.1:3000/socket.io/?id=ecad7e1a009eb4f943ead0b4db8d62c4&EIO=3&transport=websocket&sid=0RMaRoZb7U67td_2AAAD' failed: Invalid frame header
Also it runs well. There is no problem :). But i wondered.
Maybe you should check versions of socket client and server. They should be the same.

MQTT 1884 connection failed

I am using mqtt for a messaging system on my site. Well on my local machine everything works fine but on my site (production) I am getting an error:
vendor.bbaf8c4….bundle.js:1 WebSocket connection to
'ws://localhost:1884/mqtt' failed: Error in connection establishment:
net::ERR_CONNECTION_REFUSED
I am using Ubuntu within my Webserver and I gave the port 1884 free.
What this error meaning?
I am using Angular4 and I add the connection within AfterViewInit
ngAfterViewInit() {
setTimeout(()=>{
this.messageservice.createMqttConnection(this.userId);
}, 200)
}
The connection with Paho on my client site looks like:
this._client = new Paho.MQTT.Client("localhost", 1884, id.toString());
Let assume my domains is mydomain.com should I replace it with localhost?
As thrashed out in the comments:
The hostname in your app needs to point to your domain e.g. mydomain.com not localhost
localhost will always point to the machine the code is running on so is very unlikely to be what you want for a production deployment of an application.

WebSocket connection failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

I am new to WebRTC and WebSockets and was following this tutorial to create a WebRTC demo project, but I am unable to create a WebSocket connection. I have followed the same steps as mentioned in the project.
His project is running on port 8080 and he mentioned ws://localhost:9090. My project is running on port 8081, but I copied his URL ws://localhost:9090 because I didn't know the significance of 9090 and I received this error and my server is node.js. i changed local host to 8081 as well but then i am getting hand shake error.
WebSocket connection to 'ws://localhost:9090/' failed: Error in
connection establishment: net::ERR_CONNECTION_REFUSED.
Chrome doesn't allow unsecure websocket (ws) connections to localhost (only wss, so you should setup a TLS certificate for your local web/websocket server).
However the same should work fine with Firefox.
You need to use ws://yourIp:9090/, where yourIP is like 192.168.?.?.
Usually WebRTC requires a secure connection (that is https).
The error you have got is due to TLS/SSL certificates occupied, may be they are not properly configured in your project.
Provide a valid TLS/SSL certificate and also configure it correctly in project, then it will work without the above error.
try to change the port to 8080
const ws = new WebSocket('ws://localhost:8080/chat')
I guess this is a generic websocket issue.
Change the url to a dynamic name using the built-in location.host variable and change the protocol to secure websocket wss if you have set-up the TLS:
const ws = new WebSocket("wss://" + location.host + "/")
Port 9090 is used by reactotron. Probably you are using it in your project and your app cannot connect with reactotron because it is closed. Just open reactotron and the error will disappear.
also you could easily change the mappings of IP addresses to host names,
on windows go to C:\Windows\System32\drivers\etc\hosts and uncomment this line
127.0.0.1 localhost
save and restart.
WebSocket connection to 'ws://localhost:8080/' failed
Must ensure server file is running
I git this above problem
maybe you forgot to start websocket server, check it again, with configuration in my project, run:
php artisan websocket:init

Browser not connecting to server with websocket

I am hosting my app with Heroku and using websockets. When the browser sends a request the connection fails due to this error message:
Firefox can't establish a connection to the server at wss://shrouded-dawn-5557.herokuapp.com/ws
In my javascript file I create a new websocket object as:
ws = new WebSocket("ws://"+ location.host +"/ws");
Why is this not making the connection to the server.
Thanks
Solved this by enabling websockets in Heroku:
heroku labs:enable websockets -a myapp

Heroku / Which URL should I specify to point my server's Websocket port

I have a Javascript client that aims to point to my WebSocket port on my backend (Play Framework app).
I try to init the connection like this in my client:
var ws = new WebSocket("ws://myHerokuDomain:9000/api/notifications/ws");
but obtain this error (in Safari console): WebSocket network error: Refused connection
I imagine that the port may be wrong, Heroku using its own.
How to check for the port that Heroku uses when setting my Play Framework application?
I'm pointing out that I enabled websockets on Heroku using Heroku CLI, as the documentation explains.
In dev mode, the whole works using:
var ws = new WebSocket("ws://localhost:9000/api/notifications/ws");
So my problem sounds to be really about the chosen URL.
How could I fix it?
I just changed the URI to:
'ws://' + window.location.host + '/api/notifications/ws'
and it works.

Categories

Resources