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

jigsaw-tcp

v1.0.1

Published

这是使用Jigsaw重新封装的TCP套接字,提供服务端和客户端两种实例工厂

Downloads

1

Readme

Jigsaw-TCP 文档

1.1 简介

这是使用Jigsaw重新封装的TCP套接字,提供服务端和客户端两种实例工厂

1.2 动机

普通的,由操作系统接口提供的TCP套接字,虽然提供了keepAlive机制,但是间隔接近十分钟。
不适用于对资源的分配要求苛刻的环境。使用jigsaw.js封装后,所有TCP连接自带心跳包机制,
自动管理连接的存在,而通信仍然使用的是Node.js原生的TCP套接字。

其次,封装后的TCP套接字,使用jigsaw.js网络获取网络地址,轻松的发现网络内的服务端,并建立连接。

再者,由于jigsaw.js是基于JSON序列化与反序列化的,不适用于大量字节流的传送,
故本模块提供了"透明传送"的基于TCP的可靠高效字节流传送通道,jigsaw仅管理连接的存在,所以
不会影响到透传的性能。

1.2 安装

在npm项目下执行命令
npm install ZhyMc/jigsaw-tcp --save

1.3 用例

1.3.1 简单用例

server.js

const {TCPClient,TCPServer} = require("jigsaw-tcp");
const {jigsaw,domainserver} = require("jigsaw.js")("127.0.0.1","127.0.0.1");
domainserver();

let jg=new jigsaw("jgtcpserver");
let server=new TCPServer(jg);

server.on("enter",(conn,id)=>{
	
	console.log(id,"客户端加入了连接");

	conn.on("data",(data)=>{
		console.log("收到来自客户端的数据",data);

		server.broadcast("欢迎你们");
	});
});

server.on("leave",(conn,id)=>{
	console.log(id,"客户端离开了连接");
});

client.js

const {TCPClient,TCPServer} = require("jigsaw-tcp");
const {jigsaw} = require("jigsaw.js")("127.0.0.1","127.0.0.1");

let jg=new jigsaw();
let client=new TCPClient(jg,"jgtcpserver");

client.on("ready",()=>{
	console.log("连接TCP服务器成功");
	let sock=client.getSocket();

	sock.write("hello");
});

client.on("close",()=>{
	console.log("连接已断开");
})

1.3.2 流的分发

streamServer.js

const {TCPClient,TCPServer} = require("jigsaw-tcp");
const {jigsaw,domainserver} = require("jigsaw.js")("127.0.0.1","127.0.0.1");
domainserver();

let jg=new jigsaw("streamserver");
let server=new TCPServer(jg);

server.on("enter",(conn,id)=>{
		conn.on("data",(data)=>{
			server.broadcast(data);
		});
});

streamPublisher.js

const {TCPClient,TCPServer} = require("jigsaw-tcp");
const {jigsaw} = require("jigsaw.js")("127.0.0.1","127.0.0.1");

let jg=new jigsaw("streampublisher");
let publisher=new TCPClient(jg,"streamserver");
let chunkid=0;

publisher.on("ready",()=>{
	let sock=publisher.getSocket();
	setInterval(()=>{
		sock.write("hello,i am chunk "+(chunkid++));
	},100);
});

streamPlayer.js

const {TCPClient,TCPServer} = require("jigsaw-tcp");
const {jigsaw} = require("jigsaw.js")("127.0.0.1","127.0.0.1");

let jg=new jigsaw();
let player=new TCPClient(jg,"streamserver");

player.on("ready",()=>{

	let sock=player.getSocket();

	sock.on("data",(data)=>{
		console.log(data.toString());
	})
});