简体   繁体   English

Socket.io 未返回有效的 HTTP 响应

[英]Socket.io is not returning a valid HTTP response

I am using socket.io and using this guide to implement it and the server is able to start up with no errors.我正在使用 socket.io 并使用本指南来实现它,并且服务器能够无错误地启动。 But whenever I try connecting to the WebSocket from the server I am getting an error similar to this: Did not receive a valid HTTP response .但是,每当我尝试从服务器连接到 WebSocket 时,我都会收到类似以下的错误: Did not receive a valid HTTP response

I am initializing socket.io with this code:我正在使用以下代码初始化 socket.io:

const socketio = new Server(http, {
  serveClient: false,
  pingInterval: 10000,
  pingTimeout: 5000,
});

Edit:编辑:

I am trying to connect to the WebSocket with this URL: ws://localhost:8000 using Python's WebSocket package . I am trying to connect to the WebSocket with this URL: ws://localhost:8000 using Python's WebSocket package . I used their example which is this:我用他们的例子是这样的:

import asyncio
import websockets

async def connect():
    await websockets.connect("ws://localhost:8000")

asyncio.run(connect())

Check the port the server is listening to and match both client and server.检查服务器正在侦听的端口并匹配客户端和服务器。 You should avoid low ports because those are used for common known apps and your system may piss you off by using them.您应该避免使用低端口,因为它们用于常见的已知应用程序,并且您的系统可能会因使用它们而惹恼您。 5 digits should be enough 5位数应该够了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM