Skip to content

Instantly share code, notes, and snippets.

@timyhac
Created June 12, 2016 23:32
Show Gist options
  • Save timyhac/a2c217eef63063946df1e738b16961e4 to your computer and use it in GitHub Desktop.
Save timyhac/a2c217eef63063946df1e738b16961e4 to your computer and use it in GitHub Desktop.
var net = require('net');
var serverA = net.createServer();
var serverB = net.createServer();
serverA.on('connection', (socketA) => {
socketA.on('data', (data) => {
console.log('CLIENTA:', data);
});
serverB.on('connection', (socketB) => {
socketB.on('data', (data) => {
console.log('CLIENTB:', data);
});
socketA.pipe(socketB);
socketB.pipe(socketA);
});
});
PORTA = 50100
PORTB = 50101
serverA.listen(PORTA);
serverB.listen(PORTB);
@timyhac
Copy link
Author

timyhac commented Jun 12, 2016

Example: Open up three terminals and type the following commands:
Terminal 1: node TCP_DoubleAdapter.js
Terminal 2: nc 50100
Terminal 3: nc 50101

Then use either instance of netcat to create some network traffic, notice that it is being logged as raw bytes (or a Buffer() object) in the node-js application

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment