Node.js Socket.IO连接未建立
我无法建立到节点服务器中Socket.IO的连接。我的服务器已使用Socket.IO成功启动,但在连接到Socket的过程中,我没有获得控制台日志Node.js Socket.IO连接未建立,node.js,typescript,express,socket.io,Node.js,Typescript,Express,Socket.io,我无法建立到节点服务器中Socket.IO的连接。我的服务器已使用Socket.IO成功启动,但在连接到Socket的过程中,我没有获得控制台日志 this.server.listen(this.port, () => { console.log(`Server is running on ${this.port} with process id ${process.pid}`) }); this.io.on('connection', (socket: an
this.server.listen(this.port, () => {
console.log(`Server is running on ${this.port} with process id ${process.pid}`)
});
this.io.on('connection', (socket: any) => {
console.log(`Connected client on port ${this.port}`);
socket.on('messsage', (msg: Message) => {
console.log(`Data: ${msg}`);
socket.emit('message', msg);
});
socket.on('disconnect', () => {
console.log(`Client Disconnected`);
});
});
尝试更改您的代码:
var socket=io.connect('localhost')代码>
到
var socket=io.connect('http://localhost:port');代码>共享客户端代码替换您正在运行节点服务器的端口是的,我尝试了,它也在不提供端口的情况下工作。但是,现在我不断得到一个连接日志你的端口是什么?我的端口是4000所以现在你的连接正在重置?