npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-socket-rpc

v1.0.1

Published

使用nodejs开发的socket通讯RPC

Downloads

1

Readme

node-socket

使用 nodejs 开发的 socket 通讯,目前支持 tcp 协议。基本功能:断线重连、心跳检测、路由、远程调用、超时监听等。

支持客户端监听服务端的通知、事件。使用路由方式在客户端监听。

支持远程调用。服务端注册方法,客户端调用方法即可。

功能

  1. tcp 的 server 和 client 互相发送消息
  2. 消息格式处理,目前支持 json

功能说明

  1. 心跳。客户端发起,5 秒一次。10 秒没有响应就断开连接。
  2. 连接。客户端和服务端建立连接之后发送校验 token,token 验证成功则发送成功 ack。

使用

可以查看test目录下的文件

import NClient from "../src/NClient";

const ct = new NClient();

ct.listen(18000);

const sleep = (time: number) => new Promise((resolve) => setTimeout(() => resolve(), time));

ct.use("test", async function (data) {
    console.log("1", data);
    await sleep(3000);
    console.log("1_end");
    return data + 1;
});

ct.use("test", async function (data) {
    console.log("2", data);
    await sleep(2000);
    console.log("2_end");
    return data + 1;
});

服务端 API

  1. cfg。服务端的配置,保存了使用到的配置内容。
  2. listen(port = 4000, host?: string)。启动服务端的监听,传入监听的端口,可选的 hostname。
  3. notice(uid: string, group: string, data: any)。主动通知除 uid 之外该房间的所有人。
  4. sendTo(uid: string, command: string, data?: any)。给 uid 对应的客户端发送消息。
  5. sendAll(command: string, data?: any)。给所有人发送消息

客户端 API

  1. cfg。配置信息。
  2. info。当前状态信息
  3. listen(port = 3000, host?: string)。启动监听服务。
  4. retry。重新连接服务端。
  5. send(command, data, group?)。发送消息。
  6. sendGroup(data:any)。给房间群组发送消息。
  7. setGroup(group: string)。设置房间/群组的名称
  8. onNotice(fn: any)。当收到群体通知的时候。
  9. use(routeName:string, fn:any)。路由事件。
  10. call(method: string)。远程调用方法

包含的功能

  1. 客户端/服务端创建
  2. TCP 协议连接和断开
  3. 心跳检测
  4. 路由
  5. 组/房间标记
  6. 双队列服务,标记准备中和准备好的客户端
  7. 客户端发送消息到客户端,发送房间消息
  8. 远程调用。服务端注册方法,客户端调用