munet-socket
v0.1.0
Published
TCP/UDP communication for mudb
Downloads
3
Maintainers
Readme
munet-socket
TCP/UDP communications made available for mudb
, useful when building apps with frameworks like Electron.
usage
server
var tcp = require('net')
var udp = require('dgram')
var MuNetSocketServer = require('munet-socket/server').MuNetSocketServer
var MuServer = require('mudb/server').MuServer
var tcpServer = tcp.createServer()
var udpServer = udp.createSocket({
type: 'udp4',
reuseAddr: true,
})
var socketServer = new MuNetSocketServer({
tcpServer,
udpServer,
})
var muServer = new MuServer(socketServer)
tcpServer.listen(9977)
udpServer.bind(9988, '127.0.0.1')
muServer.start()
client
var tcp = require('net')
var udp = require('dgram')
var MuNetSocket = require('munet-socket/socket').MuNetSocket
var MuClient = require('mudb/client').MuClient
var socket = new MuNetSocket({
sessionId: Math.random().toString(36).substr(2),
// for TCP socket
connectOpts: {
port: 9977,
host: '127.0.0.1',
},
// for UDP socket
bindOpts: {
port: 9989,
address: '127.0.0.1',
},
})
var muClient = new MuClient(socket)
muClient.start()
table of contents
1 install
npm i munet-socket
2 api
2.1 class: MuNetSocketServer
2.1.1 new MuNetSocketServer(spec)
spec
<Object>
tcpServer
<net.Server>
the underlying TCP serverudpServer
<dgram.Socket>
the underlying UDP server
2.2 class: MuNetSocket
2.2.1 new MuNetSocket(spec)
spec
<Object>
sessionId
<string>
a unique session id used to identify the clientconnectOpts
<Object>
used by connect() to initiate a connection when the client startsbindOpts
<Object>
used by bind() to make the socket listen for datagram messages when the client startstcpSocket
<net.Socket>
optionaludpSocket
<dgram.Socket>
optional
credits
Copyright (c) 2018 He Diyi, Shenzhen Dianmao Technology Company Limited