我无法在节点服务器中建立与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: 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`);
});
});
答案 0 :(得分:1)
尝试更改您的代码:
var socket = io.connect('localhost');
到
var socket = io.connect('http://localhost:port');