socketio:客户端没有收到消息

socketio: client is not receiving message

我正在测试 socketio 以构建一个具有多个频道的小型聊天应用程序。 我已经设法将数据从客户端发送到服务器。服务器发回通道已创建。但是我的客户没有收到消息。有什么想法吗?

客户端代码: 除了 "channel_already_exists" 和 "channel_created" 这两个事件外,一切都运行良好。 服务器正在发送这些事件,但客户端似乎没有收到它们,因为我的控制台中没有显示任何内容。

document.addEventListener('DOMContentLoaded', () => {

  // Connect to websocket
  var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port);

  // When connected, the user can register his username
  socket.on('connect', () => {

    document.getElementById('new_channel').hidden = true;

    if (localStorage.username) {
      socket.emit('register', {'username': localStorage.username});
    } else {
        document.getElementById('registration').onsubmit = () => {
          const username = document.getElementById('username').value;
          localStorage.setItem('username', username);
          socket.emit('register', {'username': username});
        };
    }
  });

  socket.on('registered', () => {
    const username = localStorage.username;
    document.getElementById('registration').innerHTML = '';
    document.getElementById('new_channel').hidden = false;
    document.getElementById('welcome').innerHTML = `Welcome ${username}`;
  });

  document.getElementById('new_channel').onsubmit = () => {
    const channel_name = document.getElementById('channel_id').value;
    socket.emit('new_channel', {'channel_name': channel_name});
  };

  socket.on('channel_already_exists', () => {
    console.log('already exists');
    document.getElementById('channel_message').innerHTML = 'Channel already exists. Please select another name.';
  });

  socket.on('channel_created', channels => {
    console.log('channel created');
    document.getElementById('channel_message').innerHTML = 'Channel has been created.';
  });

});

Flask 上的服务器代码:

import os
import requests

from flask import Flask, jsonify, render_template, request
from flask_socketio import SocketIO, emit

app = Flask(__name__)
app.config["SECRET_KEY"] = os.getenv("SECRET_KEY")
socketio = SocketIO(app)

users = set()
channels = {}

@app.route("/")
def index():
    not_registered = True
    return render_template("index.html")

#Register new user
@socketio.on("register")
def on_register(data):
    print("register")
    username = data["username"]
    users.add(username)
    emit("registered")

@socketio.on("new_channel")
def on_new_channel(data):
    print("new_channel")
    channel_name = data["channel_name"]
    if channel_name in channels:
        print("channel_already_exists")
        emit("channel_already_exists")
    else:
        #create a new empty channel
        print("new_channel_created")
        channels[channel_name] = ""
        emit('channel_created', channels)

我尝试创建新频道时的客户端日志(即提交 "new_channel" 时)

engine.io-client:socket socket error {"type":"TransportError"} +5s
socket.io.min.js (2,5342)

socket.io-client:manager error +5s Error: xhr poll error

engine.io-client:socket socket close with reason: "transport error" +1ms
socket.io.min.js (2,5342)

engine.io-client:polling transport open - closing +1ms
socket.io.min.js (2,5342)

engine.io-client:polling writing close packet +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr open POST: http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1574762262046-2&sid=6108efcd5e754d6c9befdcf33af618ed +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr data 1:1 +1ms
socket.io.min.js (2,5342)

socket.io-client:manager close +3ms
socket.io.min.js (1,13697)

socket.io-client:socket close (transport error) +5s
socket.io.min.js (1,13697)

socket.io-client:manager will wait 770ms before reconnect attempt +1ms
socket.io.min.js (1,13697)

socket.io-client:manager attempting reconnect +789ms
socket.io.min.js (1,13697)

socket.io-client:manager readyState closed +0ms
socket.io.min.js (1,13697)

socket.io-client:manager opening http://127.0.0.1:5000 +0ms
socket.io.min.js (1,13697)

engine.io-client:socket creating transport "polling" +791ms
socket.io.min.js (2,5342)

engine.io-client:polling polling +1ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr poll +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr open GET: http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1574762262840-3 +1ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr data null +0ms

engine.io-client:socket setting transport polling +0ms
socket.io.min.js (2,5342)

socket.io-client:manager connect attempt will timeout after 20000 +2ms
socket.io.min.js (1,13697)

engine.io-client:socket socket error {"type":"TransportError"} +1s
socket.io.min.js (2,5342)

socket.io-client:manager connect_error +1s
socket.io.min.js (1,13697)

socket.io-client:manager reconnect attempt error +0ms
socket.io.min.js (1,13697)

socket.io-client:manager will wait 1902ms before reconnect attempt +1ms
socket.io.min.js (1,13697)

engine.io-client:socket socket close with reason: "transport error" +1ms
socket.io.min.js (2,5342)

engine.io-client:polling transport not open - deferring close +1ms
socket.io.min.js (2,5342)

socket.io-client:manager attempting reconnect +1s
socket.io.min.js (1,13697)

socket.io-client:manager readyState closed +0ms
socket.io.min.js (1,13697)

socket.io-client:manager opening http://127.0.0.1:5000 +0ms
socket.io.min.js (1,13697)

engine.io-client:socket creating transport "polling" +2s
socket.io.min.js (2,5342)

engine.io-client:polling polling +1ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr poll +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr open GET: http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1574762265792-4 +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr data null +1ms

engine.io-client:socket setting transport polling +0ms
socket.io.min.js (2,5342)

socket.io-client:manager connect attempt will timeout after 20000 +3ms
socket.io.min.js (1,13697)

engine.io-client:polling polling got data [object ArrayBuffer] +13ms

engine.io-client:socket socket receive: type "open", data "{"sid":"ca6c4332a9f347eab56882912b70a309","upgrades":[],"pingTimeout":60000,"pingInterval":25000}" +1ms
socket.io.min.js (2,5342)

engine.io-client:socket socket open +1ms
socket.io.min.js (2,5342)

socket.io-client:manager open +15ms
socket.io.min.js (1,13697)

socket.io-client:socket transport is open - connecting +3s
socket.io.min.js (1,13697)

socket.io-client:manager reconnect success +1ms
socket.io.min.js (1,13697)

engine.io-client:socket starting upgrade probes +1ms
socket.io.min.js (2,5342)

engine.io-client:socket socket receive: type "message", data "0" +0ms
socket.io.min.js (2,5342)

socket.io-parser decoded 0 as %j +8s [object Object]

connect
index.js (11,5)

engine.io-client:polling polling +2ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr poll +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr open GET: http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1574762265812-5&sid=ca6c4332a9f347eab56882912b70a309 +1ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr data null +0ms

socket.io-client:manager writing packet %j +5s [object Object]

socket.io-parser encoding packet %j +5s [object Object]

socket.io-parser encoded %j as [object Object] +0ms 2["register",{"username":"goeland"}]

engine.io-client:socket flushing 1 packets in socket +5s
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr open POST: http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1574762271133-6&sid=ca6c4332a9f347eab56882912b70a309 +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr data 37:42["register",{"username":"goeland"}] +0ms
socket.io.min.js (2,5342)

HTML1300: Une navigation s’est produite.
127.0.0.1:5000 (1,1)

socket.io-client:url parse http://127.0.0.1:5000 +0ms
socket.io.min.js (1,13697)

socket.io-client new io instance for http://127.0.0.1:5000 +0ms
socket.io.min.js (1,13697)

socket.io-client:manager readyState closed +0ms
socket.io.min.js (1,13697)

socket.io-client:manager opening http://127.0.0.1:5000 +0ms
socket.io.min.js (1,13697)

engine.io-client:socket creating transport "polling" +0ms
socket.io.min.js (2,5342)

engine.io-client:polling polling +2ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr poll +1ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr open GET: http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1574762271323-0 +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr data null +0ms

engine.io-client:socket setting transport polling +1ms
socket.io.min.js (2,5342)

socket.io-client:manager connect attempt will timeout after 20000 +4ms
socket.io.min.js (1,13697)

socket.io-client:manager readyState opening +0ms
socket.io.min.js (1,13697)

engine.io-client:polling polling got data [object ArrayBuffer] +46ms

engine.io-client:socket socket receive: type "open", data "{"sid":"ccc77d7deda843fa8a846527cb19e4db","upgrades":[],"pingTimeout":60000,"pingInterval":25000}" +3ms
socket.io.min.js (2,5342)

engine.io-client:socket socket open +1ms
socket.io.min.js (2,5342)

socket.io-client:manager open +50ms
socket.io.min.js (1,13697)

socket.io-client:socket transport is open - connecting +0ms
socket.io.min.js (1,13697)

engine.io-client:socket starting upgrade probes +0ms
socket.io.min.js (2,5342)

engine.io-client:socket socket receive: type "message", data "0" +1ms
socket.io.min.js (2,5342)

socket.io-parser decoded 0 as %j +0ms [object Object]

connect
index.js (11,5)

socket.io-client:manager writing packet %j +3ms [object Object]

socket.io-parser encoding packet %j +1ms [object Object]

socket.io-parser encoded %j as [object Object] +0ms 2["register",{"username":"goeland"}]

engine.io-client:socket flushing 1 packets in socket +2ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr open POST: http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1574762271378-1&sid=ccc77d7deda843fa8a846527cb19e4db +1ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr data 37:42["register",{"username":"goeland"}] +1ms
socket.io.min.js (2,5342)

engine.io-client:polling polling +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr poll +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr open GET: http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1574762271379-2&sid=ccc77d7deda843fa8a846527cb19e4db +1ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr data null +0ms

engine.io-client:polling polling got data [object ArrayBuffer] +36ms

engine.io-client:socket socket receive: type "message", data "2["registered",null]" +2ms
socket.io.min.js (2,5342)

socket.io-parser decoded 2["registered",null] as %j +41ms [object Object]

socket.io-client:socket emitting event %j +44ms registered,

registered
index.js (26,5)

engine.io-client:polling polling +3ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr poll +1ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr open GET: http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1574762271422-3&sid=ccc77d7deda843fa8a846527cb19e4db +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr data null +1ms

new_channel
index.js (34,5)

socket.io-client:manager writing packet %j +5s [object Object]

socket.io-parser encoding packet %j +5s [object Object]

socket.io-parser encoded %j as [object Object] +0ms 2["new_channel",{"channel_name":"channel 3"}]

engine.io-client:socket flushing 1 packets in socket +5s
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr open POST: http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1574762276888-4&sid=ccc77d7deda843fa8a846527cb19e4db +1ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr data 46:42["new_channel",{"channel_name":"channel 3"}] +1ms
socket.io.min.js (2,5342)

HTML1300: Une navigation s’est produite.
127.0.0.1:5000 (1,1)

socket.io-client:url parse http://127.0.0.1:5000 +0ms
socket.io.min.js (1,13697)

socket.io-client new io instance for http://127.0.0.1:5000 +0ms
socket.io.min.js (1,13697)

socket.io-client:manager readyState closed +0ms
socket.io.min.js (1,13697)

socket.io-client:manager opening http://127.0.0.1:5000 +0ms
socket.io.min.js (1,13697)

engine.io-client:socket creating transport "polling" +0ms
socket.io.min.js (2,5342)

engine.io-client:polling polling +1ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr poll +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr open GET: http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1574762277050-0 +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr data null +1ms

engine.io-client:socket setting transport polling +0ms
socket.io.min.js (2,5342)

socket.io-client:manager connect attempt will timeout after 20000 +3ms
socket.io.min.js (1,13697)

socket.io-client:manager readyState opening +0ms
socket.io.min.js (1,13697)

0: Unable to get property 'SavePersonalAndPaymentData' of undefined or null reference
Autoformfill_ContentScript.js (1,1)

engine.io-client:polling polling got data [object ArrayBuffer] +43ms

engine.io-client:socket socket receive: type "open", data "{"sid":"0409f655ccc642f68322c4a9f64c3b66","upgrades":[],"pingTimeout":60000,"pingInterval":25000}" +2ms
socket.io.min.js (2,5342)

engine.io-client:socket socket open +0ms
socket.io.min.js (2,5342)

socket.io-client:manager open +46ms
socket.io.min.js (1,13697)

socket.io-client:socket transport is open - connecting +0ms
socket.io.min.js (1,13697)

engine.io-client:socket starting upgrade probes +1ms
socket.io.min.js (2,5342)

engine.io-client:socket socket receive: type "message", data "0" +0ms
socket.io.min.js (2,5342)

socket.io-parser decoded 0 as %j +0ms [object Object]

connect
index.js (11,5)

socket.io-client:manager writing packet %j +2ms [object Object]

socket.io-parser encoding packet %j +0ms [object Object]

socket.io-parser encoded %j as [object Object] +0ms 2["register",{"username":"goeland"}]

engine.io-client:socket flushing 1 packets in socket +2ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr open POST: http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1574762277100-1&sid=0409f655ccc642f68322c4a9f64c3b66 +1ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr data 37:42["register",{"username":"goeland"}] +0ms
socket.io.min.js (2,5342)

engine.io-client:polling polling +1ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr poll +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr open GET: http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1574762277101-2&sid=0409f655ccc642f68322c4a9f64c3b66 +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr data null +0ms

engine.io-client:polling polling got data [object ArrayBuffer] +41ms

engine.io-client:socket socket receive: type "message", data "2["registered",null]" +2ms
socket.io.min.js (2,5342)

socket.io-parser decoded 2["registered",null] as %j +45ms [object Object]

socket.io-client:socket emitting event %j +47ms registered,

registered
index.js (26,5)

engine.io-client:polling polling +3ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr poll +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr open GET: http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1574762277148-3&sid=0409f655ccc642f68322c4a9f64c3b66 +1ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr data null +1ms

engine.io-client:socket writing ping packet - expecting pong within 60000ms +25s
socket.io.min.js (2,5342)

engine.io-client:socket flushing 1 packets in socket +1ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr open POST: http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1574762302107-4&sid=0409f655ccc642f68322c4a9f64c3b66 +1ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr data 1:2 +0ms
socket.io.min.js (2,5342)

engine.io-client:polling polling got data [object ArrayBuffer] +17ms

engine.io-client:socket socket receive: type "pong", data "undefined" +1ms
socket.io.min.js (2,5342)

engine.io-client:polling polling +1ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr poll +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr open GET: http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=1574762302126-5&sid=0409f655ccc642f68322c4a9f64c3b66 +0ms
socket.io.min.js (2,5342)

engine.io-client:polling-xhr xhr data null +0ms

服务器日志:

C:\Users\rober\project2>flask run
 * Serving Flask app "application.py"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
[2019-11-26 10:57:44,233] WARNING in __init__: Flask-SocketIO is Running under Werkzeug, WebSocket is not available.
Server initialized for threading.
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Invalid session e0e081d67cbf4189b990c1dc103da589
127.0.0.1 - - [26/Nov/2019 10:57:44] "GET /socket.io/?EIO=3&transport=polling&t=1574762243279-331&sid=e0e081d67cbf4189b990c1dc103da589 HTTP/1.1" 400 -
f3cc277e7bec49c8b2eba1272d102a6c: Sending packet OPEN data {'sid': 'f3cc277e7bec49c8b2eba1272d102a6c', 'upgrades': [], 'pingTimeout': 60000, 'pingInterval': 25000}
f3cc277e7bec49c8b2eba1272d102a6c: Sending packet MESSAGE data 0
127.0.0.1 - - [26/Nov/2019 10:57:44] "GET /socket.io/?EIO=3&transport=polling&t=1574762264065-380 HTTP/1.1" 200 -
f3cc277e7bec49c8b2eba1272d102a6c: Received packet MESSAGE data 2["register",{"username":"robert"}]
received event "register" from f3cc277e7bec49c8b2eba1272d102a6c [/]
register
127.0.0.1 - - [26/Nov/2019 10:57:44] "POST /socket.io/?EIO=3&transport=polling&t=1574762264385-381&sid=f3cc277e7bec49c8b2eba1272d102a6c HTTP/1.1" 200 -
emitting event "registered" to f3cc277e7bec49c8b2eba1272d102a6c [/]
f3cc277e7bec49c8b2eba1272d102a6c: Sending packet MESSAGE data 2["registered",null]
127.0.0.1 - - [26/Nov/2019 10:57:44] "GET /socket.io/?EIO=3&transport=polling&t=1574762264393-382&sid=f3cc277e7bec49c8b2eba1272d102a6c HTTP/1.1" 200 -
Invalid session e0e081d67cbf4189b990c1dc103da589
127.0.0.1 - - [26/Nov/2019 10:57:45] "POST /socket.io/?EIO=3&transport=polling&t=1574762265345-332&sid=e0e081d67cbf4189b990c1dc103da589 HTTP/1.1" 400 -
ca6c4332a9f347eab56882912b70a309: Sending packet OPEN data {'sid': 'ca6c4332a9f347eab56882912b70a309', 'upgrades': [], 'pingTimeout': 60000, 'pingInterval': 25000}
ca6c4332a9f347eab56882912b70a309: Sending packet MESSAGE data 0
127.0.0.1 - - [26/Nov/2019 10:57:45] "GET /socket.io/?EIO=3&transport=polling&t=1574762265792-4 HTTP/1.1" 200 -
44e90573522c46f583a5811c21a2cf97: Sending packet OPEN data {'sid': '44e90573522c46f583a5811c21a2cf97', 'upgrades': [], 'pingTimeout': 60000, 'pingInterval': 25000}
44e90573522c46f583a5811c21a2cf97: Sending packet MESSAGE data 0
127.0.0.1 - - [26/Nov/2019 10:57:47] "GET /socket.io/?EIO=3&transport=polling&t=1574762267360-333 HTTP/1.1" 200 -
44e90573522c46f583a5811c21a2cf97: Received packet MESSAGE data 2["register",{"username":"robert"}]
received event "register" from 44e90573522c46f583a5811c21a2cf97 [/]
register
127.0.0.1 - - [26/Nov/2019 10:57:48] "POST /socket.io/?EIO=3&transport=polling&t=1574762267414-334&sid=44e90573522c46f583a5811c21a2cf97 HTTP/1.1" 200 -
emitting event "registered" to 44e90573522c46f583a5811c21a2cf97 [/]
44e90573522c46f583a5811c21a2cf97: Sending packet MESSAGE data 2["registered",null]
127.0.0.1 - - [26/Nov/2019 10:57:48] "GET /socket.io/?EIO=3&transport=polling&t=1574762267420-335&sid=44e90573522c46f583a5811c21a2cf97 HTTP/1.1" 200 -
ca6c4332a9f347eab56882912b70a309: Received packet MESSAGE data 2["register",{"username":"goeland"}]
received event "register" from ca6c4332a9f347eab56882912b70a309 [/]
register
127.0.0.1 - - [26/Nov/2019 10:57:51] "POST /socket.io/?EIO=3&transport=polling&t=1574762271133-6&sid=ca6c4332a9f347eab56882912b70a309 HTTP/1.1" 200 -
emitting event "registered" to ca6c4332a9f347eab56882912b70a309 [/]
ca6c4332a9f347eab56882912b70a309: Sending packet MESSAGE data 2["registered",null]
127.0.0.1 - - [26/Nov/2019 10:57:51] "GET /socket.io/?EIO=3&transport=polling&t=1574762265812-5&sid=ca6c4332a9f347eab56882912b70a309 HTTP/1.1" 200 -
127.0.0.1 - - [26/Nov/2019 10:57:51] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [26/Nov/2019 10:57:51] "GET /static/index.js HTTP/1.1" 200 -
ccc77d7deda843fa8a846527cb19e4db: Sending packet OPEN data {'sid': 'ccc77d7deda843fa8a846527cb19e4db', 'upgrades': [], 'pingTimeout': 60000, 'pingInterval': 25000}
ccc77d7deda843fa8a846527cb19e4db: Sending packet MESSAGE data 0
127.0.0.1 - - [26/Nov/2019 10:57:51] "GET /socket.io/?EIO=3&transport=polling&t=1574762271323-0 HTTP/1.1" 200 -
ccc77d7deda843fa8a846527cb19e4db: Received packet MESSAGE data 2["register",{"username":"goeland"}]
received event "register" from ccc77d7deda843fa8a846527cb19e4db [/]
register
127.0.0.1 - - [26/Nov/2019 10:57:51] "POST /socket.io/?EIO=3&transport=polling&t=1574762271378-1&sid=ccc77d7deda843fa8a846527cb19e4db HTTP/1.1" 200 -
emitting event "registered" to ccc77d7deda843fa8a846527cb19e4db [/]
ccc77d7deda843fa8a846527cb19e4db: Sending packet MESSAGE data 2["registered",null]
127.0.0.1 - - [26/Nov/2019 10:57:51] "GET /socket.io/?EIO=3&transport=polling&t=1574762271379-2&sid=ccc77d7deda843fa8a846527cb19e4db HTTP/1.1" 200 -
ccc77d7deda843fa8a846527cb19e4db: Received packet MESSAGE data 2["new_channel",{"channel_name":"channel 3"}]
received event "new_channel" from ccc77d7deda843fa8a846527cb19e4db [/]
127.0.0.1 - - [26/Nov/2019 10:57:56] "GET / HTTP/1.1" 200 -
new_channel
127.0.0.1 - - [26/Nov/2019 10:57:56] "POST /socket.io/?EIO=3&transport=polling&t=1574762276888-4&sid=ccc77d7deda843fa8a846527cb19e4db HTTP/1.1" 200 -
{}
new_channel_created {}
emitting event "channel_created" to ccc77d7deda843fa8a846527cb19e4db [/]
ccc77d7deda843fa8a846527cb19e4db: Sending packet MESSAGE data 2["channel_created","channel 3"]
127.0.0.1 - - [26/Nov/2019 10:57:56] "GET /socket.io/?EIO=3&transport=polling&t=1574762271422-3&sid=ccc77d7deda843fa8a846527cb19e4db HTTP/1.1" 200 -
127.0.0.1 - - [26/Nov/2019 10:57:56] "GET /static/index.js HTTP/1.1" 200 -
0409f655ccc642f68322c4a9f64c3b66: Sending packet OPEN data {'sid': '0409f655ccc642f68322c4a9f64c3b66', 'upgrades': [], 'pingTimeout': 60000, 'pingInterval': 25000}
0409f655ccc642f68322c4a9f64c3b66: Sending packet MESSAGE data 0
127.0.0.1 - - [26/Nov/2019 10:57:57] "GET /socket.io/?EIO=3&transport=polling&t=1574762277050-0 HTTP/1.1" 200 -
0409f655ccc642f68322c4a9f64c3b66: Received packet MESSAGE data 2["register",{"username":"goeland"}]
received event "register" from 0409f655ccc642f68322c4a9f64c3b66 [/]
register
127.0.0.1 - - [26/Nov/2019 10:57:57] "POST /socket.io/?EIO=3&transport=polling&t=1574762277100-1&sid=0409f655ccc642f68322c4a9f64c3b66 HTTP/1.1" 200 -
emitting event "registered" to 0409f655ccc642f68322c4a9f64c3b66 [/]
0409f655ccc642f68322c4a9f64c3b66: Sending packet MESSAGE data 2["registered",null]
127.0.0.1 - - [26/Nov/2019 10:57:57] "GET /socket.io/?EIO=3&transport=polling&t=1574762277101-2&sid=0409f655ccc642f68322c4a9f64c3b66 HTTP/1.1" 200 -

根据您提供的日志,问题是由您的应用程序设计错误引起的。

客户端请求通过网络表单创建新频道。表单使用 GET 或 POST 请求提交数据,这会导致浏览器删除当前页面,然后重新加载表单提交请求响应附带的页面。当浏览器重新加载页面时,它会丢弃所有连接,包括 Socket.IO link。这就是您的客户未收到因提交此表单而产生的消息的原因。

我的建议是您将表单提交更改为使用 AJAX,以便浏览器将其作为后台请求发送,而不会导致页面重新加载。