小编Oct*_*icu的帖子

如何为NodeJS设置einaros/ws模块以接受wss(安全ws)连接?

我使用NodeJS的eniaros/ws模块使用网络套接字在iOS应用程序和NodeJS服务器之间实时通信.

该应用程序运行正常,但现在我必须使用wss保护服务器和iOS应用程序之间的通信.我有快速SSL证书和密钥,我在服务器上使用以下代码:

var fs = require('fs');

var cfg = {
    ssl: true,
    port: 8081,
    ssl_key: 'key.key',
    ssl_cert: 'cert.crt'
};

var httpServ = ( cfg.ssl ) ? require('https') : require('http');

var app      = null;

// dummy request processing
var processRequest = function( req, res ) {

    res.writeHead(200);
    res.end("All glory to WebSockets!\n");
};

if ( cfg.ssl ) {

    app = httpServ.createServer({

        // providing server with  SSL key/cert
        key: fs.readFileSync( cfg.ssl_key ),
        cert: fs.readFileSync( cfg.ssl_cert )

    }, processRequest ).listen( cfg.port ); …
Run Code Online (Sandbox Code Playgroud)

ssl wss web-services websocket node.js

12
推荐指数
1
解决办法
4013
查看次数

标签 统计

node.js ×1

ssl ×1

web-services ×1

websocket ×1

wss ×1