Skip to content

Instantly share code, notes, and snippets.

@fand fand/tcp2udp.js
Last active Jul 4, 2019

Embed
What would you like to do?
Forward TCP to UDP
#!/usr/bin/env node
const net = require('net');
const dgram = require('dgram');
if (process.argv.length !== 4) {
console.error(`
Usage:
node tcp2udp.js <TCP_SRC_PORT> <UDP_DST_PORT>
`);
process.exit(-1);
}
// Get ports
const pIn = process.argv[2] | 0;
const pOut = process.argv[3] | 0;
// Create UDP Client
const client = dgram.createSocket('udp4');
// Create TCP Server
const tcpServer = net.createServer(socket => {
socket.on('data', (d) => {
client.send(d, pOut);
});
});
// Bind
tcpServer.listen(pIn);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.