1.1.28 • Published 4 years ago

divcom v1.1.28

Weekly downloads
17
License
MIT
Repository
-
Last release
4 years ago

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)
1.1.28

4 years ago

1.1.27

4 years ago

1.1.26

4 years ago

1.1.25

4 years ago

1.1.24

4 years ago

1.1.23

4 years ago

1.1.22

4 years ago

1.1.21

4 years ago

1.1.20

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.0.1

4 years ago

1.1.1

4 years ago

1.0.0

4 years ago