WebFaction
Community site: login faq

hello, i have a chatting application in my Django website project using web faction server, so i followed the multi chat example channels-examples but when i try to connect and create the hard shake i got this error:

[Error] WebSocket connection to 'ws://gadgetron.store/Pchat/' failed: Unexpected response code: 404

================================

settings.py:

redis_host = os.environ.get('REDIS_HOST', 'localhost')
CHANNEL_LAYERS = {
  "default": {
      "BACKEND": "asgi_redis.RedisChannelLayer",
      "CONFIG": {"hosts": [(redis_host, 6379)],},
      "ROUTING": "chatbot.routing.channel_routing",},}

====================================

PP_chat_index.js:

$(window).load(function() {
    $messages.mCustomScrollbar();
    setTimeout(function() {
        welcomingMessage();
        var ws_path = "/Pchat/";
        var webSocketBridge = new channels.WebSocketBridge();
        webSocketBridge.connect(ws_path);
        webSocketBridge.listen(function(data) {
        if (data.join){
              msg = $('.message-input').val();
              webSocketBridge.send({
                   "command": "send",
                   "room": data.join,
                   "message": msg});}
        else if (data.message){chatMessage(data);}});},100);});

========================================

chatbot/routing.py(in the same folder as the settings.pt):

routing = [include(chat_routing, path=r"^/Pchat"),]
channel_routing = [include("Pchat.routing.websocket_routing", path=r"^/Pchat"),include("Pchat.routing.custom_routing"),]

========================================

Pchat/routing.py(in the chatting app):

 websocket_routing = [ route("websocket.connect", ws_connect),route("websocket.receive", ws_receive),route("websocket.disconnect", ws_disconnect),]

================

PS: i have created a Custom websockets app (listening on port) using the control panel , and as the support team said to my is to make my application listen to that port....but i don' know how ?!

asked 23 Aug, 17:28

eman_saad's gravatar image

eman_saad
112
accept rate: 0%


You'll have to stop your Django app's Apache instance, since you can't serve websockets from our back-end Apache setup.

Instead, run the app using Django's "runserver" management command, and pass it the port assigned to your websockets app, for example if the port was 12345:

python3.5 manage.py runserver 12345

That will start the Django channels daphne web server and 4 worker threads.

Then, change your site config in our control panel to serve your websockets app instead of the actual Django app.

After a few minutes, the site should be up and running with functioning websockets

I also recommend you either run Redis on a filesystem socket instead of a port, or create a new "Custom app (listening on port)" application to get a different port assignment for Redis.

permanent link

answered 23 Aug, 23:51

seanf's gravatar image

seanf ♦♦
11.9k21333
accept rate: 37%

thank you, well my site consists of 3 app and two of them uses http:// request and the third is ws:// request all of them are inside of Django project/website . so my questions are: 1- if i change the site config? does it affect the other apps?,2- how can i change the site confg?

(25 Aug, 22:57) eman_saad eman_saad's gravatar image

How do you serve this locally when you develop? Do you run 'runserver' once? If we know more about each app and how you typically serve it we can shed more light on the issue. If you don't want to discuss it in public you may submit a support ticket.

(26 Aug, 21:44) johns ♦♦ johns's gravatar image

i have developed the website locally and now switch to deploying the website and using the ssh connection in console and cont. developing the app

(27 Aug, 13:23) eman_saad eman_saad's gravatar image

That is not what I mean, I assumed you develop it locally and are using SSH to try to deploy it. You said you have 3 apps, What commands do you run to develop/start each of them locally?

(27 Aug, 21:24) 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:

×891
×4
×4

question asked: 23 Aug, 17:28

question was seen: 354 times

last updated: 27 Aug, 21:24

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2017 PARAGON INTERNET GROUP LIMITED
WEBFACTION IS A SERVICE OF PARAGON INTERNET GROUP LIMITED
REGISTERED IN ENGLAND AND WALES 7573953 - VAT REGISTRATION NUMBER 182147021
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM