I tried to insert lz4 in between to increase the actual speed of the AIR line from area A to the office. Therefore, it was necessary to have a mechanism for sending and receiving standard input / output via TCP. I found the best tool when I looked it up nc (netcat) (See the device http://www.intellilink.co.jp/sites/default/files/imported/article/column/sec-network01.png) However, if you download it in Area A, it will be kicked by Buster. I can't ignore it and just record that I made this guy in JAVA.
PG:
ncJava.java
package ncjava;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
public class ncJava {
public static void main(String[] args) throws Exception{
if (args.length!=2) {
System.err.println(
"USAGE: ncJava toSTD/toTCP TCPIP:PORT"
);
return;
}
if (args[0].toUpperCase().equals("TOSTD")) {
//Server TCP to STDOUT
ServerSocket ss = new ServerSocket(
new Integer(args[1].replaceAll("^([^:]+):(.+)$", "$2")) //PortPart
,0
,InetAddress.getByName(args[1].replaceAll("^([^:]+):(.+)$", "$1")) //IPpart
);
Socket as = null;
System.err.println("stby:"+ss+" to STDOUT");
try {
while((as = ss.accept()) != null ) {
System.err.println("recive from TCP:"+as);
byte buf[] = new byte[1024];
int r = 0;
while ((r=as.getInputStream().read(buf))!=-1) {
System.out.write(buf,0,r);
System.out.flush();
}
System.err.println("disconnect TCP:"+as);
}
} finally {if (ss != null) ss.close();}
return;
}else if (args[0].toUpperCase().equals("TOTCP")) {
//Server STDIN to TCP
Socket sc = new Socket(
InetAddress.getByName(args[1].replaceAll("^([^:]+):(.+)$", "$1")) //IPpart
,new Integer(args[1].replaceAll("^([^:]+):(.+)$", "$2")) //PortPart
);
System.err.println("stby to:"+sc+" from STDIN");
try {
byte buf[] = new byte[1024];
int r = 0;
while ((r=System.in.read(buf))!=-1) {
System.err.println("recive from STDIN:"+r);
sc.getOutputStream().write(buf,0,r);
sc.getOutputStream().flush();
}
System.err.println("disconnect STDIN:");
} finally {if (sc != null) sc.close();}
return;
}
}
}
test results: Sender E:\MrServer>echo "testa" |java -jar ncJava.jar TOTCP localhost:9999 stby to:Socket[addr=localhost/127.0.0.1,port=9999,localport=54726] from STDIN recive from STDIN:10 disconnect STDIN:
E:\MrServer> Receiver E:\MrServer>java -jar ncJava.jar TOSTD localhost:9999 stby:ServerSocket[addr=localhost/127.0.0.1,port=0,localport=9999] to STDOUT recive from TCP:Socket[addr=/127.0.0.1,port=54726,localport=9999] "testa" disconnect TCP:Socket[addr=/127.0.0.1,port=54726,localport=9999]
Sender E:\MrServer>type file.txt "engbJapan" "hhhhhhh"
E:\MrServer>java -jar ncJava.jar TOTCP localhost:9999 <file.txt stby to:Socket[addr=localhost/127.0.0.1,port=9999,localport=54728] from STDIN recive from STDIN:26 disconnect STDIN:
E:\MrServer> Receiver recive from TCP:Socket[addr=/127.0.0.1,port=54728,localport=9999] "engbJapan" "hhhhhhh" disconnect TCP:Socket[addr=/127.0.0.1,port=54728,localport=9999]
that's all.
Recommended Posts