1.1.28 • Published 6 years ago

divcom v1.1.28

Weekly downloads
17
License
MIT
Repository
-
Last release
6 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

6 years ago

1.1.27

6 years ago

1.1.26

6 years ago

1.1.25

6 years ago

1.1.24

6 years ago

1.1.23

6 years ago

1.1.22

6 years ago

1.1.21

6 years ago

1.1.20

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.0.1

6 years ago

1.1.1

6 years ago

1.0.0

6 years ago