@svrooij/tcp-server
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

tcp-server

This library is to make it a bit easier to host a TCP socket.

Install

npm install --save @svrooij/tcp-server

API

Create a server with this code.

const TcpServer = require('@svrooij/tcp-server')

const server = new TcpServer({ port: 3000, host: '0.0.0.0' })
server.start()

server.on('textReceived', (text, remoteAddress) => {
  console.log('%s -> %s', remoteAddress, text)
})

server.publish('Publish message').then(success => {
  console.log('Message send ', success ? ' successfully' : 'failed')
})

process.on('SIGINT', () => {
  server.stop()
})

Connect to the server.

> telnet 192.168.1.20 3000
Trying 192.168.1.20...
Connected to my-computer.localdomain.
Escape character is '^]'.

Readme

Keywords

Package Sidebar

Install

npm i @svrooij/tcp-server

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

235 kB

Total Files

16

Last publish

Collaborators

  • svrooij