Created
June 12, 2016 23:32
-
-
Save timyhac/a2c217eef63063946df1e738b16961e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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