shardus-net
A library for sending and receiving JSON messages over raw TCP sockets.
Fundamentally, this is just a networked event emitter. Under the hood, the library is using a UUID system to correlate messages to their response handler in order to facilitate the simulation of a request/response system. Hence, the library can only be used to send data to and from other servers using this library (for now).
Installation
You can install shardus net via npm:
npm i gitlab:shardus/shardus-net
Local Development
If you're working on the shardus-net
package, make sure to run the command npm run build
manually to ensure both TypeScript and Rust files are generated.
For publishing a release to NPM, simply run npm run release
command.
Usage
Javascript
const port = 1234
const address = 'localhost'
const sn = require('shardus-net')({ port, address })
Typescript
import * as ShardusNet from 'shardus-net'
const port = 1234
const address = 'localhost'
const sn = ShardusNet.createNetwork({ port, address })
sn.send
const destinationPort = 53
const destinationAddress = 8.8.8.8
const data = { algebraic: 'Yeah!' }
const protocol = await sn.send(destinationPort, destinationAddress, data)
const destinationPort = 53
const destinationAddress = 8.8.8.8
const data = { mathematical: 'Alright!' }
const timeout = 10000
const onResponse = data => console.log(data)
const onTimeout = () => throw new Error('timed out :(')
await sn.listen(() => {})
const protocol = await sn.send(destinationPort, destinationAddress, data, timeout, onResponse, onTimeout)
sn.listen
const server = await sn.listen((data, remote, protocol, respond) => {
await respond(data)
})
sn.stopListening
await sn.stopListening(servers)
Contributing
Contributions are very welcome! Everyone interacting in our codebases, issue trackers, and any other form of communication, including chat rooms and mailing lists, is expected to follow our code of conduct so we can all enjoy the effort we put into this project.
Special thanks to Aaron Sullivan (aasullivan1618@gmail.com) for the contributions that became the base for this library.
You can find them here at https://gitlab.com/Shardus/shardus-quic-net.git