Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Socket.IO连接未建立_Node.js_Typescript_Express_Socket.io - Fatal编程技术网

Node.js Socket.IO连接未建立

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

我无法建立到节点服务器中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`);
        });
    });
尝试更改您的代码:
var socket=io.connect('localhost')


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

共享客户端代码替换您正在运行节点服务器的端口是的,我尝试了,它也在不提供端口的情况下工作。但是,现在我不断得到一个连接日志你的端口是什么?我的端口是4000所以现在你的连接正在重置?