@superhero/socket
v0.5.2
Published
TCP socket connection, client and server
Downloads
3
Readme
Socket
Licence: MIT
A socket connection for "server to server" communication.
Install
npm install @superhero/socket
...or just set the dependency in your package.json
file:
{
"dependencies":
{
"@superhero/socket": "*"
}
}
Example Application
A simple example to get started follows.
const
SocketFactory = require('@superhero/socket'),
socketFactory = new SocketFactory,
// Debug = require('@superhero/debug'),
// log = new Debug({ debug:true }),
log = console,
server = socket.createServer(log),
client = socket.createClient(log),
port = 18200,
event = 'foobar',
body = { foo:'bar' }
server.listen(port)
client.connect(port)
client.emit(event, body)
server.on(event, (context, data) => context.emit(event, body))
client.on(event, (context, data) =>
{
// if you need to close the connection, then...
client.client.end()
server.server.close()
})