Skip to content

superhero/js.socket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published