sarsjits / tcp-relayer

Node.js module to relay raw TCP data from one socket to another

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tcp-relayer

Node.js module to relay raw TCP data from one socket to another. Essentially, it should work like the following:

  • A server is started on some port
  • It waits for two TCP clients to connect
  • As soon as it receives two connections, it starts relaying data from the first socket to second one
  • Data is relayed until one of the clients disconnects

Pre-requisites

  • NodeJS version >= 6.9.1
  • NPM version >= 3.10.8
  • Telnet or any other tool that allows you to connect to remote computer over a TCP/IP network

Installation

$ npm install https://github.com/sarsjits/tcp-relayer.git

Usage

var relay = require('tcp-relayer');

relay.relayServer(portNumber);

Example

  • Use the above module in your Node app as mentioned in the usage. This will create a server listening over the mentioned port.

  • Run the app

  • Image 01

  • Now to connect to the running server, we will use telnet.

  • Client 1

  • Image 02

  • Server

  • Image 03

  • Sending message to the server even no other TCP client is yet connected.

  • Client 1

  • Image 04

  • Server

  • Image 05

  • As soon as another client connects to the server, buffered messages are sent to the client. The two clients can now communicate via server.

  • Client 2

  • Image 06

  • Server

  • Image 07

  • If the connection between two TCP clients is already established. The server will drop the new incoming connection.

  • Client 3

  • Image 08

  • Server

  • Image 09

Future Work

  • Extending to multiple pair of connections
  • Standalone app supporting Graphical Interface.

Suggestions

Provide the feedback at sarsjits@gmail.com

About

Node.js module to relay raw TCP data from one socket to another

License:MIT License


Languages

Language:JavaScript 100.0%