SockJS-nodeNode.JS Server

联合创作 · 2023-09-23 18:53

SockJS-node is a Node.js server side counterpart of SockJS-client browser library written in CoffeeScript.

To install sockjs-node run:

npm install sockjs

(If you see rbytes dependecy failing, don't worry, it's optional, SockJS-node will work fine without it.)

An simplified echo SockJS server could look more or less like:

var http = require('http');
var sockjs = require('sockjs');

var echo = sockjs.createServer();
echo.on('connection', function(conn) {
    conn.on('data', function(message) {
        conn.write(message);
    });
    conn.on('close', function() {});
});

var server = http.createServer();
echo.installHandlers(server, {prefix:'/echo'});
server.listen(9999, '0.0.0.0');
浏览 6
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报