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 🙏

© 2026 – Pkg Stats / Ryan Hefner

coa-tcp

v1.0.2

Published

一个轻量的TCP服务框架,是COA核心库组成之一

Downloads

1

Readme

coa-tcp

GitHub license npm version npm downloads PRs Welcome

一个轻量的 TCP 服务框架,是 COA 核心库组成之一

可以快速创建一个 TCP 服务,支持单片机或物联网设备、跨平台 TCP 应用的连接。

特性

  • 简单轻量 基于 Node.js 内置的 Net 模块,简单轻量,不依赖于其他第三方库
  • 自动管理连接池 自动维护管理客户端连接池,无需关心连接和释放的问题,专注于收发消息和业务逻辑的开发
  • TypeScript 全部使用 TypeScript 书写,类型约束、IDE 友好

快速开始

安装

yarn add coa-tcp

快速开始

import { CoaClientPool, CoaTcp } from 'coa-tcp'

// 创建一个客户端连接池
const clientPool = new CoaClientPool()

// 创建一个tcp服务
const tcpServer = new CoaTcp(clientPool, 5000)

// 启动服务
tcpServer.start()

当控制台输出类似提示,则说明 TCP 服务已经正常启动,可以接受客户端的连接了

[TCP] Listening on port 5000

自定义客户端

import { Socket } from 'net'
import { CoaClient, CoaClientPool, CoaTcp } from 'coa-tcp'

// 自定义客户端
class CustomClient extends CoaClient {
  // 接收到数据
  async onData(raw: Buffer) {
    // 收到数据后要处理的事情
  }

  // 上线
  async onOnline(deviceId: string) {
    super.onOnline(deviceId)
    // 客户端上线要处理的事情
  }

  // 下线
  async onOffline(deviceId: string) {
    super.onOffline(deviceId)
    // 客户端下线要处理的事情
  }
}

// 自定义客户端连接池
class CustomClientPool extends CoaClientPool<CustomClient> {
  // 生成一个自定义的客户端
  newClient(socket: Socket) {
    return new CustomClient(
      socket,
      `custom-id-${++this.increment}`,
      'CustomClient'
    )
  }
}

// 创建一个客户端连接池
const clientPool = new CustomClientPool()

// 创建一个tcp服务
const tcpServer = new CoaTcp(clientPool, 5000)

// 启动服务
tcpServer.start()