How to use the sockjs.listen function in sockjs

To help you get started, we’ve selected a few sockjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Clouda-team / Cloudajs / sumeru / server / run.js View on Github external
var globalServer = http.createServer(function(req, res) {
    	if (typeof fsServer =='function'){
    		return fsServer(req,res);
    	}
    	
    }).listen(PORT, function() {
        fw.log('Server Listening on ' + PORT);
    });

    // register the server to group
    //groupManager.register([{addr:config.get('selfGroupManagerAddr') || '0.0.0.0',port:config.get('selfGroupManagerPort') || (parseInt(PORT) + 3000)}]);

 // =====================  NET MESSAGE DISPATCHER , WANG SU ================== // 
    //start websocket server
    
    var sock = sockjs.listen(globalServer, {
        prefix : '/socket'
    });

    sock.on("connection", function(conn) {
        
        if(!conn){
            fw.log('no connection object.');
            return;
        }
        
        conn.on("data", function(msg){
            //FIXME 做跨域连接检测和授权检查
            //后面的pk判断是用于如果server的pk变化,中断后重新交换公钥的时候不加密,所以此处遇到'{}'不解密。
            if (fw.config.get("rsa_enable") && msg.substring(0,1) !== "{") {
                msg = fw.myrsa.decrypt(msg);
            }

sockjs

SockJS-node is a server counterpart of SockJS-client a JavaScript library that provides a WebSocket-like object in the browser. SockJS gives you a coherent, cross-browser, Javascript API which creates a low latency, full duplex, cross-domain communication

MIT
Latest version published 3 years ago

Package Health Score

76 / 100
Full package analysis