@superhero/socket

0.5.2 • Public • Published

Socket

Licence: MIT


npm version

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()
})

Readme

Keywords

Package Sidebar

Install

npm i @superhero/socket

Weekly Downloads

0

Version

0.5.2

License

MIT

Unpacked Size

2.11 MB

Total Files

167

Last publish

Collaborators

  • superhero