Skip to content

About

基于 express 中间件思想的 socket server

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

sockets-server

通用 sockets server 框架

概述

基于 express 中间件原理实现通用 socket server. 支持如下功能.

  • 客户端会话管理
  • 自定义路由解析
  • 自定义包解析
  • 自定义中间件扩展 ...

快速入门

  1. 安装包

    npm install sockets-server
  2. 在项目根目录创建 demo.js 复制 demo.js 到 demo.js

  3. 在 package.json 的 scripts 属性中添加如下内容

       {
         "demo": "export DEBUG='socket:*';node demo.js"
       }
  4. 安装 debug 包

    npm run debug 
  5. 运行范例脚本

    npm run demo

该 demo 模拟了 socket 客户端和服务端的通信. 效果如下图:

原理说明

开发与验证

使用 Node.js 20 或 22+ 安装锁定的开发依赖并运行测试:

npm ci
npm test
npm run build

测试包含本机 TCP 连接与自定义解析器。构建只在 npm_dist/ 生成包,不会发布到 npm。 发布需要在单独审核构建产物后手动执行。

About

基于 express 中间件思想的 socket server

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages