divcom
TypeScript icon, indicating that this package has built-in type declarations

1.1.28 • Public • Published

divcom

Auto divide or combine stream data

Install

npm install --save divcom

Usage and example

import {Socket, Server} from "net"
import {Passive, Initiative, Event} from "divcom"

function handPacket(packet:Buffer){
    console.log(`packet(${packet.toString()})`)
}

function startServer(port:number){
    const server = new Server()
    server.on("connection", (s:Socket)=>{
        const link = new Passive(s) // or new Initiative(s)
        link.on(Event.Packet, (packet:Buffer)=>{
            handPacket(packet)
        })
        link.write(Buffer.from("from server"))
    })
    server.listen(port)
}

startServer(3000)
import {Socket, Server} from "net"
import {Passive, Initiative, Event} from "divcom"

function handPacket(packet:Buffer){
    console.log(`packet(${packet.toString()})`)
}

function startClient(port:number){
    const s = new Socket()
    s.on("connect", ()=>{
        const p = new Passive(s) // or new Initiative(s)
        p.on(Event.Packet, (pakcet:Buffer)=>{
            handPacket(pakcet)
        })
        p.write(Buffer.from("from client"))
        
    })
    s.connect(port)
}

startClient(3000)

Dependents (0)

Package Sidebar

Install

npm i divcom

Weekly Downloads

2

Version

1.1.28

License

MIT

Unpacked Size

12.5 kB

Total Files

13

Last publish

Collaborators

  • wlx199x