具有socket.io配置的Express生成器

时间:2022-09-22 19:43:44

Below code is my current configuration, it worked but I'm confused.

下面的代码是我目前的配置,它工作但我很困惑。

server side

var server = require("http").Server(express);  
var io = require("socket.io")(server);
server.listen(5000);
io.on('connection', function(client) {


});

cilent

var socket = io.connect('http://localhost:5000');

Why we need to create another server for socket at port 5000 for an application? can't socket use 3000? which is the express's running port. I removed the line of server.listen('5000') and do server.listen() and try connect to port 3000 at client side it doesn't work.

为什么我们需要为端口5000为应用程序创建另一个套接字服务器?不能套接字使用3000?这是快递的运行端口。我删除了server.listen('5000')的行并执行server.listen()并尝试连接到客户端的端口3000它不起作用。

1 个解决方案

#1


0  

By default express 4 create a server and run it bin/www. I solved this issue by commenting out server.listen(port); in that file.

默认情况下,express 4创建一个服务器并运行它bin / www。我通过注释掉server.listen(port)解决了这个问题;在那个文件中。

#1


0  

By default express 4 create a server and run it bin/www. I solved this issue by commenting out server.listen(port); in that file.

默认情况下,express 4创建一个服务器并运行它bin / www。我通过注释掉server.listen(port)解决了这个问题;在那个文件中。