Node + socket.io + Typescript无法使其正常工作

时间:2019-09-18 10:13:41

标签: node.js typescript socket.io

此代码有什么问题?当我尝试与客户端连接时,没有任何反应,我正在使用简单Web套接字客户端扩展。使用 websocket.io 一切都很好。

import * as express from 'express';
import * as http from 'http';
import * as io from 'socket.io';

export class AppClass{   
    private _port:number=3080;

    constructor(){
        const expressServer = express();              

        const server = http.createServer(expressServer);

        let webSocket:io.Server = io(server);
        webSocket.on('connection',
            (s:io.Socket)=>{
                console.log('socket.io connection...', s);
                s.on('message',
                    (msg:string)=>{
                        console.log(msg);
                    })
            }
        );    

        server.listen(
            this._port,
            ()=>{
                console.log('Server is listening on port ', this._port);
            }
        );

    }    
}

0 个答案:

没有答案