WebFaction
Community site: login faq

Hello,

Who are using the package Django-Channels (https://channels.readthedocs.io/en/stable/) ?

This package uses Redis and Websocket. I correctly configured Redis and it runs in background (with a daemon). But I have a problem with websocket, when I try to access on a page of my website I have this error (in the web browser) :

" WebSocket connection to 'ws://nameOfMySite.com/' failed: Error during WebSocket handshake: Unexpected response code: 200 "

I don't know why... I have create a custom websocket app (listening on port) and I add it to my website.

The websocket creation is in a file Javascript :

  1. var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws";
  2. var ws_path = ws_scheme + '://' + window.location.host + window.location.pathname;
  3. var socket = new WebSocket(ws_path);

The error above is linked to the line 3 (var socket = new WebSocket(ws_path);).

Why Have I this error ?

If I forgot something, please let me know.

asked 27 Nov '16, 12:47

yass's gravatar image

yass
111
accept rate: 0%


You must open the port, and than connect on that port.

ws://nameOfMySite.com:12345/

Where 12345 is the port assigned to you by the control panel.

permanent link

answered 27 Nov '16, 22:13

johns's gravatar image

johns ♦♦
4.8k29
accept rate: 22%

As of mid 2014, it's no longer necessary to open a port for ws apps.

(10 May, 18:59) seanf ♦♦ seanf's gravatar image

Firstly, thank you for your response but now I have a new error :

"WebSocket connection to 'ws://projup.com:12345/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED"

The IP assigned (12345) is the IP of my custom websocket application.

I have only one website configured with Django and it contains the custom websocket application.

The IP of my website is contained in open port IPs.

When I write (with ssh in Webfaction environment) "netstat -lnp |grep 12345", I have nothing.

Thank you...

permanent link

answered 27 Nov '16, 23:50

yass's gravatar image

yass
111
accept rate: 0%

If you run,

ps -u $USER

Does it show your servers running? If not you will need to troubleshoot the server by checking its logs to see why it is not starting.

(28 Nov '16, 02:30) johns ♦♦ johns's gravatar image

When I run this command, I have many servers running (4 http.worker and one redis-server) but how can I know the PID of the websocket server ? In the logs (~/logs/user) I don't have errors...

(28 Nov '16, 19:24) yass yass's gravatar image

I use this line to match pid to port, (although it is not very clean)

netstat -antuwp | egrep "(^[^t])|(^tcp.*LISTEN)" | grep 12345

where 12345 is the port number. This should give you the pid(after LISTEN, with the proc path) and than you can feed that into ps to get more info. You can also try reading your application logs or writing a small test script which runs on the server and checks if the application is running on localhost. The general debugging process for this is to verify the server is really running, any number of paths can be taken for this. If it is and the port is not working open a ticket and we can check the fire wall. If the application is not running, than this is the source of the current issue.

(28 Nov '16, 22:29) johns ♦♦ johns's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×877
×24
×1

question asked: 27 Nov '16, 12:47

question was seen: 773 times

last updated: 10 May, 18:59

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2016 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM