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

kk-ws

v2.1.11

Published

这是一个包含客户端和服务端的WebSocket框架

Downloads

58

Readme

KK-WS

这是一个包含客户端和服务端的WebSocket框架

GETTING STARTED

  1. npm install kk-ws --save
const Server = require('kk-ws')

const server = new Server({
    withClient:true,
    encrypt:true //这里设置之后websocket会被加密,开发过程可以设为false
})


server.on("connection",socket=>{
    socket.on('news',(content,callbackFn)=>{
        socket.emit("news",content)
    })
})

server.listen(4400)

目标 (能替代socket.io的适合我们公司的websocket框架)

打开示例

打开终端: npm test 打开终端: node test/index.js

浏览器打开 http://localhost:1234 打开F12

原理

连接

  1. 客户端首先通过http获取sid

  2. 客户端通过获取到的sid,连接websocket

  3. 如果webosocket连接不上,会走两条连接,send走post,receive走long polling (不做了,数据传输比较频繁的情况下,服务器压力会很大)

为什么用http获取sid这一步,websocket的连接建立是比较粗暴的,连接建立失败基本上就是1006错误,不会透露错误原因,通过http建立预连接可以在出错时得到详细的错误信息

服务器

  1. 服务器端实现了http和websocket两种的链接方式

  2. 服务器分两种模式独立运行模式,和模块运行模式

  3. 服务器支持消息录制,根据channel区分

独立模式

  1. 同机房的多服务器模型,使用redis的publish subscribe机制,向服务器分发

模块运行模式

  1. connector模块,专门用于建立websocket连接,广播和单播,不处理业务逻辑(可以多服务器)

  2. backend模块,单服务器运行,通过 RabbitMQ/websocket 与connector模块建立,收到connector的消息,处理后返还给connector