divcom
v1.1.28
Published
Auto divide or combine stream data
Downloads
8
Readme
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)