WebFaction
Community site: login faq

a have a Django chat application using web sockets and channels,the wecbokect connection is establish as you can see here:

[USER@webXXX src]$ python3.5 manage.py runserver 22783 Performing system checks...
Django version 1.11, using settings 'chatbot.settings'
2017-09-04 16:53:05,478 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.disconnect, websocket.receive
2017-09-04 16:53:05,479 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.disconnect, websocket.receive
2017-09-04 16:53:05,479 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.disconnect, websocket.receive
2017-09-04 16:53:05,480 - INFO - server - HTTP/2 support not enabled (install the http2 and tls Twisted extras)
2017-09-04 16:53:05,480 - INFO - server - Using busy-loop synchronous mode on channel layer
2017-09-04 16:53:05,480 - INFO - server - Listening on endpoint tcp:port=22783:interface=127.0.0.1
[2017/09/04 16:54:09] WebSocket HANDSHAKING /webscok/ [127.0.0.1:42846]
[2017/09/04 16:54:09] WebSocket CONNECT /webscok/ [127.0.0.1:42846]

But , when i tried echoing the messages back to me it work perfectly. Now i moved on creating a chat server that adds a new client to the chat group and broadcast and incoming messages to all connected clients , i have configure and installed everything but the Group() doesn't work and nothing is happing and no error be shown so i don't know where is the problem?

chat.js:

$(window).load(function() {
   $messages.mCustomScrollbar();
   var ws_path = "/webscok/";
   var socket = new WebSocket("ws://" + window.location.host + ws_path);
   socket.onmessage = function(e) {chatMessage(e.data);}
   $('.message-submit').click(function() {
                                      msg = $('.message-input').val();
                                      socket.send(msg);
                                      insertMessage(msg);});
   $(window).on('keydown', function(e) {
                                      if (e.which == 13) {
                                          msg = $('.message-input').val();
                                          socket.send(msg);
                                          insertMessage(msg);}});
  setTimeout(function() {
      welcomingMessage();}, 100);
});

consumers.py:

import json
from channels import Channel , Group
from channels.auth import http_session_user, channel_session_user, channel_session_user_from_http
from channels.sessions import channel_session

def ws_connect(message):
     message.reply_channel.send({"accept": True})
     Group('chat').add(message.reply_channel)
def ws_receive(message):
    Group('chat').send({"text": message.content['text'],})
def ws_disconnect(message):
   Group('chat').discard(message.reply_channel)

routing.py:

from channels.routing import route
from Pchat.consumers import ws_connect, ws_disconnect, ws_receive

channel_routing = [
    route("websocket.connect", ws_connect,path=r"^/webscok"),
    route("websocket.disconnect", ws_disconnect),
    route("websocket.receive", ws_receive),
]

settings.py:

    CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "asgi_redis.RedisChannelLayer", 
        "CONFIG": {
            "hosts": ['unix:///home/USER/webapps/gadgetron/var/redis.sock',],},
        "ROUTING": "chatbot.routing.channel_routing",
    },
}

cht.html:

{% load static from staticfiles %}
<!DOCTYPE html>
<html >
<head>
  <meta charset="UTF-8">
  <title>??????? ?????</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
  <link rel='stylesheet prefetch' href='https://fonts.googleapis.com/css?family=Open+Sans'>
<link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/malihu-custom-scrollbar-plugin/3.1.3/jquery.mCustomScrollbar.min.css'>
  <link rel="icon" href="/static/icon.png">
  <link rel="favicon.ico" href="/static/icon.png">
 <link rel="stylesheet" href="/static/css/chatbot_style.css">
</head>
<body>
<div class="chat">
  <div class="chat-title">
    <h1>???? .. online now</h1>
    <h2>??????????? ???????</h2>
    <figure class="avatar">
      <img src="/static/icon.png" /></figure>
  </div>
  <div class="messages">
    <div class="messages-content"></div>
  </div>
  <div class="message-box">
    <textarea type="text" class="message-input" placeholder="???? ????? ???"></textarea>
    <button type="submit" class="message-submit">?????</button>
  </div>

</div>
<div class="bg"></div>
  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/malihu-custom-scrollbar-plugin/3.1.3/jquery.mCustomScrollbar.concat.min.js'></script>
<script src="/static/js/channels/js/websocketbridge.js"></script>
<script src="/static/js/PP_chat_index.js"></script>

asked 05 Sep, 18:21

eman_saad's gravatar image

eman_saad
112
accept rate: 0%

edited 06 Sep, 02:03

johns's gravatar image

johns ♦♦
5.0k29

I edited your post to remove the user and web-server from the info. I wont post a full answer as we are also troubleshooting this in a ticket I think, I remember replying to your ticket asking for a way to reproduce the issue in real-time, even with the code examples here we could likely isolate where you are having the issue if we could trigger the error you are reporting and place it in context.

(06 Sep, 02:06) johns ♦♦ johns's gravatar image

thank you, but how i can do that ... because the console,the terminal and the log files doesn't show any error and i have double check every thing

(06 Sep, 13:56) eman_saad eman_saad's gravatar image

Also, i tried to search if the log files to see if there is any error that could help me and i did found an error in the front end log file that says: 2017/09/06 15:52:04 [error] 34481#0: *16309337 connect() failed (111: Connection refused) while connecting to upstream, client: 37.105.247.121, server: gadgetron.store, request: "GET /webscok/ HTTP/1.1", upstream: "http://127.0.0.1:22783/", host: “gadgetron.store"

(06 Sep, 17:20) eman_saad eman_saad's gravatar image

That's the wrong log file. The one to check is in ~/logs/user.

(06 Sep, 17:32) seanf ♦♦ seanf's gravatar image
Be the first one to answer this question!
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
×27
×4

question asked: 05 Sep, 18:21

question was seen: 220 times

last updated: 06 Sep, 17:32

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