I used to make nc (netcat) with JAVA normally

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.



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) {
					"USAGE: ncJava toSTD/toTCP TCPIP:PORT"
		if (args[0].toUpperCase().equals("TOSTD")) {
			//Server TCP to STDOUT
			ServerSocket ss = new ServerSocket(
					new Integer(args[1].replaceAll("^([^:]+):(.+)$", "$2")) //PortPart
					,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.err.println("disconnect TCP:"+as);
			} finally {if (ss != null) ss.close();}

		}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);
				System.err.println("disconnect STDIN:");
			} finally {if (sc != null) sc.close();}

test results: Sender E:\MrServer>echo "testa" |java -jar ncJava.jar TOTCP localhost:9999 stby to:Socket[addr=localhost/,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/,port=0,localport=9999] to STDOUT recive from TCP:Socket[addr=/,port=54726,localport=9999] "testa" disconnect TCP:Socket[addr=/,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/,port=9999,localport=54728] from STDIN recive from STDIN:26 disconnect STDIN:

E:\MrServer> Receiver recive from TCP:Socket[addr=/,port=54728,localport=9999] "engbJapan" "hhhhhhh" disconnect TCP:Socket[addr=/,port=54728,localport=9999]

that's all.

Recommended Posts

I used to make nc (netcat) with JAVA normally
I tried to make Basic authentication with Java
I tried to interact with Java
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
I tried to make an Android application with MVC now (Java)
I did Java to make (a == 1 && a == 2 && a == 3) always true
I want to use java8 forEach with index
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
I tried to break a block with java (1)
I tried to implement TCP / IP + BIO with JAVA
[Java 11] I tried to execute Java without compiling with javac
I tried to make a login function in Java
I tried to implement Stalin sort with Java Collector
I want to transition screens with kotlin and java!
Java to play with Function
Java --How to make JTable
Connect to DB with Java
Connect to MySQL 8 with Java
I tried to make an introduction to PHP + MySQL with Docker
I tried to create a java8 development environment with Chocolatey
I tried to modernize a Java EE application with OpenShift.
[Beginner] Try to make a simple RPG game with Java ①
I just wanted to make a Reactive Property in Java
I tried to make Java Optional and guard clause coexist
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I tried to make a client of RESAS-API in Java
I want to implement various functions with kotlin and java!
[Java] I want to test standard input & standard output with JUnit
Easy to make LINE BOT with Java Servlet Part 2: I tried image messages and templates
A story that I struggled to challenge a competition professional with Java
Java to learn with ramen [Part 1]
I want to make a button with a line break with link_to [Note]
[Java] Points to note with Arrays.asList ()
How to make a Java container
I want to return to the previous screen with kotlin and java!
Dare to challenge Kaggle with Java (1)
I tried UDP communication with Java
Design patterns to enjoy with frequently used Java libraries --Factory pattern
What I learned with Java Gold
I wanted to make JavaFX programming easier with the Spring Framework
I tried to summarize Java learning (1)
[Java] I want to perform distinct with the key in the object
Java, arrays to start with beginners
I tried to summarize Java 8 now
How to make a Java array
I tried to make a group function (bulletin board) with Rails
[Java] Java was said to be okay to concatenate strings with +, so I checked
I want to display images with REST Controller of Java and Spring!
I tried to make an automatic backup with pleasanter + PostgreSQL + SSL + docker
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (PowerMockito edition)
[iOS] I tried to make a processing application like Instagram with Swift
I want to create a dark web SNS with Jakarta EE 8 with Java 11
I used Docker to solidify the template to be developed with spring boot.
[Java] I want to make it easier because it is troublesome to input System.out.println.
I tried to make a talk application in Java using AI "A3RT"
I want to ForEach an array with a Lambda expression in Java
How to make an app with a plugin mechanism [C # and Java]
Interface Try to make Java problem TypeScript 7-3
How to make a Java calendar Summary
I tried to summarize the methods used