Here you can find the source of sendCommand(final String command, final int monitorPort)
public static String sendCommand(final String command, final int monitorPort) throws IOException
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.Socket; public class Main { public static String sendCommand(final String command, final int monitorPort) throws IOException { try (Socket socket = new Socket("127.0.0.1", monitorPort); BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()))) { writer.write(command);/* w w w . java 2 s . co m*/ writer.newLine(); writer.flush(); return reader.readLine(); } } }