[2025-06-25] Recording and Sharing about Independently Development – WebSocket on Node.js / 独立开发记录与分享 – Node.js服务器上的WebSocket

Independent Development

Connect to WebSocket provided by a Node.js server

Error

I used to connect to my Node.js server through WebSocket, but after I merged code to others, the connection was failed.

Solution

In fact it was an error introduced while merging code.

const server = http.createServer(app);
setupWebSocket(server);
// wrong code:
// app.listen(PORT, “0.0.0.0”, …);
// right code:
server.listen(PORT, “0.0.0.0”, …);

The wrong code will start a different server from the WebSocket server.
If not AI, I think it will take me years to find this error…

Main Site(Under building)

Nonpareil Me

Related Platforms

(Github Issues) / (Notion) / (Blog)

Advertisement

(A website to optimize your resume and to boost your career: Nonpareil.me)


独立开发

连接到Node.js服务器提供的WebSocket

问题

我用Node.js提供了WebSocket,前端一直可以连接,但是当我把代码和其它人的合并之后,就再也连不上了。

解决方案

实际上这是一个合并代码时引入的简单错误。

const server = http.createServer(app);
setupWebSocket(server);
// 错误代码:
// app.listen(PORT, “0.0.0.0”, …);
// 正确代码:
server.listen(PORT, “0.0.0.0”, …);

错误的代码会启动一个不同的没有在运行WebSocket的server。
很简单,但是如果没有AI帮忙,我都不知道得多久才能找到这个问题所在……

主站(建设中)

[Nonpareil Me]{https://nonpareil.me}

相关平台

(Github Issues) / (Notion) / (Blog)

推广

(优化简历,助力职场:Nonpareil.me)

发表评论

您的邮箱地址不会被公开。 必填项已用 * 标注

滚动至顶部