gpt4 book ai didi

node.js - Meteor 和 Socket IO 端口

转载 作者:太空宇宙 更新时间:2023-11-03 23:27:22 24 4
gpt4 key购买 nike

我已经包含了this到我的项目,它允许在我的项目中使用套接字 io 库。我将发布部分代码

 // Start server
try {
server.listen(8080);
console.log("Server is litsnening for 8080 port");
} catch (e) {
console.error(e);
}

如您所见,我的服务器正在监听 8080 端口。问题是当我使用 meteor 命令为我的 meteor 应用程序加星标时,它在端口 3000 上启动。 enter image description herehttp://localhost:3000/ 那么现在我如何告诉客户端在 8080 端口连接呢?如果我可以使用相同的端口那就太棒了,但这是不可能的。那么服务器如何监听连接呢? 3000 或 8080 端口?

最佳答案

我有点晚了,但今天我需要在 meteor 应用程序中实现 socket.io,并且我想对两者使用相同的端口

import { WebApp } from 'meteor/webapp';
import socketIO from 'socket.io';

const io = socketIO(WebApp.httpServer);

io.on('connection', function(socket) {
console.log('new socket client');
});

到目前为止,这个解决方案似乎有效,但我不知道这是否是一个好的做法。

关于node.js - Meteor 和 Socket IO 端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42292654/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com