Socket
Book a DemoInstallSign in
Socket

udp-node-fisher

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

udp-node-fisher

可靠UDP

1.0.4
latest
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

udp-node-fisher

介绍

主要针对lei-udp这个库重新用ts重写了一遍,优化了结构,修复了原有分包确认包action错误以及模拟丢包中重试部分没有模拟的问题。 这个库主要是对udp协议的封装,增加了udp自动分包,ping,可靠udp传输的功能。 ps:由于传输数据是协议格式,必须前后端都用这个库才可以。

更新列表

安装教程

npm i udp-node-fisher --save

使用说明

客户端使用

import { UDP } from "udp-node-fisher";
var udp_client = new UDP({});
udp_client.on('close', function () {
    console.log('udp client closed.')
})

//错误处理
udp_client.on('error', function () {
    console.log('some error on udp client.')
})

// 接收消息
udp_client.on('data', (rinfo,msg) => {
    // console.log(`receive message from ${rinfo.address}:${rinfo.port}:${msg}`);
    let param = JSON.parse(msg.toString());
    return param;
})

this._udp.send('127.0.0.1', 4000, {}, () => {
     //发送成功回调
});

this._udp.sendR('127.0.0.1', 4000, {}, () => {
     //服务器响应收到回调
});

服务端使用

//创建 udp server
this._server = new UDP({ port: port });
// 监听端口
this._server.on('listening', ()=>{

});

//接收消息
this._server.on('data', (linker,msg:Buffer)=>{
    let strmsg = msg.toString();
    let request: any;
    try {
        request = JSON.parse(strmsg);
    } catch (e) {
        console.error(`接收到错误数据${strmsg}-----来源${linkInfo.address}:${linkInfo.port}`);
        return;
    }
    console.log(`收到[${linkInfo.address}:${linkInfo.port}]:${strmsg}`);
});
//错误处理
this._server.on('error', (err)=>{
    
});

Keywords

node

FAQs

Package last updated on 23 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.