Created
December 9, 2010 10:53
-
-
Save KOBA789/734598 to your computer and use it in GitHub Desktop.
TCP Tester
This file contains 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
#!/usr/bin/env node | |
/* | |
* node tcpTester.js で立ち上げて、始めに、 | |
* host port encoding(utf-8) SSL_Enable(false) | |
* で接続します。 | |
* あとは行ベースでゴニョゴニョ。 | |
* | |
* 紹介/利用はご自由に。ご利用は自己責任で。著作権は @KOBA789 に帰属します。 | |
* なにかあれば @KOBA789 まで。 | |
*/ | |
var crypto = require('crypto'), | |
net = require('net'); | |
console.log = function (chunk) { | |
process.stdout.write(chunk); | |
} | |
var stdin = process.openStdin(); | |
stdin.setEncoding('utf-8'); | |
stdin.once('data', function (chunk) { | |
var data = String(chunk).split(/\s+/); | |
var encoding = String(data[2]) || 'utf-8'; | |
var isSSL = Boolean(data[3]); | |
var socket = net.createConnection(data[1], data[0]); | |
if (isSSL) socket.setSecure(crypto.createCredentials({})); | |
socket.setEncoding(encoding); | |
socket.on('connect', function () { | |
socket.on('data', function (chunk) { | |
console.log(chunk); | |
}); | |
stdin.on('data', function (chunk) { | |
socket.write(chunk); | |
}); | |
socket.on('end', function (chunk) { | |
process.exit(); | |
}); | |
socket.on('error', function (chunk) { | |
process.exit(1); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment