I have followed some tutorials and built a chat application using nodejs,socket io and django which works fine locally in ubuntu server running in virtual machine. But, when i try to run this in my live site,hosted on webfaction, i see a 'handshake error'. I have installed nodejs using this tutorial -- http://www.ravelrumba.com/blog/how-to-install-node-js-on-webfaction/
client:
$(document).ready(function(){
var socket = io.connect('http://node.username.webfactional.com');
socket.on('connect',function(){
console.log('connect'); });});
server:
var http = require('http');
var server = http.createServer().listen(30699,'127.0.0.1');
var io = require('socket.io').listen(server);
i get this error in the browser console on trying to connect:
GET http://node.username.webfactional.com/socket.io/1/?t=1378464435111 500 (Internal Server Error)
and a 'handshake error' error in node console.
Any suggestions could be very helpful to me.Thank you.
Related
I am running my server on a ec2 instance with gunicorn and nginx. My site and project works but it gives error connecting with websockets. I am using Websocket in js to connect with Django channels. On my local server everything was working correctly but after deploying my site. Websockets are not working and giving me this error
Error during WebSocket handshake: Unexpected response code: 502.
What I have tried uptil now...
I have installed redis and daphne. Configured daphne setting in nginx configuration.
My Server is running on 80 port and I have set daphne on 8001 port.
When I start daphne service it runs for some time and then disconnect/fail automatically but when it is running my websockets still cant connect.
Any kind of help will be great for me.
I am trying to install code-server 3.6.2 on a cloud platform. I have tried both AWS and digitalocean machines but in both systems, I can open code server but it gives an error "WebSocket close with status code 1006".
I have followed the procedure from https://www.digitalocean.com/community/tutorials/how-to-set-up-the-code-server-cloud-ide-platform-on-ubuntu-20-04
code-server uses websocket to connect.Do you use HTTPS?
If so, you should Use wss to forward ws.like this:
// forward websocket (wss -> ws)
httpsServer.on('upgrade', function (req, socket, head) {
proxy.ws(req, socket, head, {
target: 'ws://...',
ws: true
})
})
Usually this and other errors happen when you use code server locally
To solve it you can use the --link parameter that gives you a url with temporary https, or you can also use ngrok
//Option 1
code-server --host 127.0.0.1 --bind-addr 0.0.0.0:9000 --auth password --link
//Option 2
code-server --host 127.0.0.1 --bind-addr 0.0.0.0:9000 --auth password
ngrok http 9000
I created a simple nodejs app on the aws-ec2 server following the instructions. The code is:
#!/usr/bin/env nodejs
var http = require('http');
http.createServer(function (req, res)
{
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8080, '138.68.244.XXX');
//138.68.244.XXX is the IP of my ec2 server
console.log('Server running at http://localhost:8080/');
After I started the app by the command: node hello.js
I got output:
Server running at http://localhost:8080/
I was able to curl the URL:
curl http://138.68.244.XXX:8080
to get “Hello World” on the server itself, however, when I tried:
http://138.68.244.XXX:8080
in a browser, I got:
ERRCONNECTIONTIMED_OUT
Please help,
Thank you!
Check this FAQ entry (how to open a port on an instance with a public IP). As port 8080 is not a standard HTTP port, you probably need to update the security group and ACL.
I developed my web application with Angular 8. The backend is a rest api that I developed with django rest framework and it's viewed just in the localhost. I tested it and it works fine. For example the service http://127.0.0.1:8000/api/devices gives a list of devices. It gives a good results if I test it with browser or curl command.
I'm calling this service from my angular app. I executed the angular app with the command: ng serve --host 0.0.0.0 --port 4201
If I open the web application in the browser with http://127.0.0.1:4201/api/devices the service /api/devices is well called and I get the list of devices in my web page. but if I open the web application with my LAN IP address like that http://192.168.1.59:4201/api/devices, so I get HTTP 400 bad request error in my console.
And the same error is shown in django server traces: GET /api/devices/ HTTP/1.1" 400 26
After some searches in the internet I concluded that this error is frequently coming from angular app especially the proxy:
my proxy config file proxy.config.json is:
{
"/api" : {
"target": "http://localhost:8000",
"secure": false
}
}
I mad other searches and I found an answer to similar question Angular 6 call localhost API and after following the angular doc https://angular.io/guide/build in "Proxying to a backend server" section then I modified my proxy config file to:
{
"/api": {
"target": "http://localhost:8000",
"secure": false,
"pathRewrite": {
"^/api": ""
}
}
}
Has any one an idea what can be the main cause of the issue? and how I can fix it?
ng serve --host 0.0.0.0 --port 4201 --disable-host-check
I have built a Flask-Socketio server application which works as expected when I connect to it using a javascript client via ws, but fails to connect via wss, both on localhost and when running on my Digital Ocean server. With wss, I get this error in the console (client running on Heroku):
index.js:14 WebSocket connection to 'wss://[IP_ADDRESS]/socket.io/?
EIO=3&transport=websocket' failed: Error in connection establishment:
net::ERR_CONNECTION_REFUSED
When the client is running on localhost, it causes this error:
polling-xhr.js:265 GET https://localhost:5000/socket.io/?
EIO=3&transport=polling&t=MW6p0Aj net::ERR_SSL_PROTOCOL_ERROR
The flask server is running with
socketio.run(app, host='0.0.0.0', port=443) # production
or
socketio.run(app, host="localhost", port=5000) # localhost
At first I thought it could have been an issue with the Nginx configuration or server ports not being open, however the same issue occurs with the server running on Localhost, so now I'm suspecting an issue with my Flask-Socketio application
Turns out I didn't have SSL certificates configured. I followed the instructions in this guide to create a self-signed SSL certificate and configure Nginx to use it. Now works as expected.
There are lot of issues with Flask-Socketio. With Apache server it almost doesn't works.But you are using Nginx. Refer following link on github.
https://github.com/miguelgrinberg/Flask-SocketIO/issues/298#issuecomment-408682588