Skip to content

sysdevs/generic-node-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Generic TCP server

This project aims at creating a TCP server that will automatically handle various events that occur. See the example and events section for more info.

Example

Here's a simple echo server implementation

const network = require('network')
const server = new network.Server()

server.on('session-data', (session, data) => {
    console.log(`${session} sent ${data}`)
    session.write(data)
    // await session.write(data) [waits for the data to be written]
})

await server.bind(1234)

// ... some time later

await server.unbind()

Events

Server

  • 'session-connected' - a new connection has been accepted
  • 'session-disconnected' - a connection has been closed
  • 'session-error' - an error was produced by a session's socket
  • 'session-data' - data was received
  • 'session-timeout' - no incoming/outgoing traffic had happened within a timeframe

License

GNU General Public License v3.0
See LICENSE

About

A generic framework for working with TCP servers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published