代码之家  ›  专栏  ›  技术社区  ›  kmiklas

ERR\ u CONNECTION\ u densed-在React中Python Websocket到SocketIO

  •  0
  • kmiklas  · 技术社区  · 5 年前

    为什么拒绝此Websocket连接?

    服务器是一个基于pythonwebsockets浏览器的Python脚本示例[1,4];客户端是SocketIO[2,3]。下面是参考文献中的例子。

    • pythonwebsockets和带有SocketIO的React应用程序都运行在同一个Linux centos7平台上。
    • Python WebSockets:
      ... IP设置为127.0.0.1
      ... 端口设置为1717
      ... 使用ws(不是wss)

    • ... IP设置为127.0.0.1
      ... 端口设置为1717
      ... 使用ws(不是wss)
    1. 连接成功升级-101交换协议为绿色
    2. 使用IP地址从另一台计算机在浏览器中成功查看React应用程序;例如:192.168.21.33:1700
    3. 无CORS或访问控制允许原点集(WebSocket不需要)

    Chrome、Edge和FF中的测试都会产生类似的消息:

    Chrome: 
    Websocket connection to 'ws://127.0.0.1:1717/' failed: Error in connection 
    establishment: net::ERR_CONNECTION_REFUSED
    
    Edge:
    SCRIPT12029: WebSocket Error: Network Error 12029, A connection
    with the server could not be established 
    
    Firefox:
    Firefox can't establish a connection to the server at ws://127.0.0.1:1717/.
    

    工具书类

    1. https://websockets.readthedocs.io/en/stable/intro.html#browser-based-example
    2. https://medium.com/dailyjs/combining-react-with-socket-io-for-real-time-goodness-d26168429a34
    3. https://github.com/socketio/socket.io
    4. https://github.com/aaugustin/websockets
    0 回复  |  直到 5 年前