Server and client help in java
<p>I am new to java and have a doubt, I have two servers and a client, the client sends a message to server one and server returns a response that pro customer, I wonder how do I answer that this return of server serves one of the input parameter pro server two, I'll put the code here to see if someone knows the answer, thanks.</p>

<p>Client:</p>

<pre><code>import java.io.*;
import java.net.*;


public class MyClient {
    public static void main(String[] arguments) throws Exception {
        String mesg;
        String host;
        String port;
        if (arguments.length == 3) {
            host = arguments[0];
            port = arguments[1];
            mesg = arguments[2];
        } else {
            System.out.println("Usage: java MyClient host port message");
            return;
        }
        try {
            Socket digit = new Socket(host, Integer.parseInt(port));//cria o       socket digit
            digit.setSoTimeout(20000);

            // Envia identificacao
            BufferedOutputStream bos = new  BufferedOutputStream(digit.getOutputStream());//cria um stream de saida
            PrintWriter os = new PrintWriter(bos, false);
            os.println(mesg);
            os.flush();

            // recebe informacoes
            BufferedReader in = new BufferedReader(new  InputStreamReader(digit.getInputStream()));//recebe as informações enviadas pelo server



            boolean eof = false;
            while (!eof) {
                String line = in.readLine();
                if (line != null)
                    System.out.println(line);
                else
                    eof = true;
            }
            digit.close();//fecha o socket
        } catch (IOException e) {
            System.out.println("IO Error: " + e.getMessage());
        }
    }
}
</code></pre>

<p>Server1:</p>

<pre><code>import java.io.*;
import java.net.*;


public class MyServer extends Thread {
    private ServerSocket sock;

    public MyServer(int port) {
        super();
        try {
            sock = new ServerSocket(port);
            System.out.println("MyServer running at port " + port);
        } catch (IOException e) {
            System.out.println("Error: couldn't create socket.");
            System.exit(1);
        }
    }

    public void run() {
        Socket client = null;

        while (true) {
            if (sock == null)
                return;
            try {
                client = sock.accept();
                // Recebendo identificacao
                BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
                String c = in.readLine();
                System.out.println(c);

                // Enviando Informacoes
                BufferedOutputStream bos = new BufferedOutputStream(client.getOutputStream());
                PrintWriter os = new PrintWriter(bos, false);
                os.println(executar(c));
                os.flush();
                os.close();
                client.close();
            } catch (IOException e) {
                System.out.println("Error: couldn't connect to client.");
                System.exit(1);
            }
        }
    }

    private String executar(String conteudo) {
        return conteudo.toUpperCase();
    }

    public static void main(String[] arguments) {
        int port = 4000;
        if (arguments.length == 1) {
            port = Integer.parseInt(arguments[0]);
        }
        MyServer server = new MyServer(port);
        server.start();
    }
}
</code></pre>

<p>Server2:</p>

<pre><code>import java.io.*;
import java.net.*;


public class MyServer2 extends Thread {
    private ServerSocket sock;

    public MyServer2(int port) {
        super();
        try {
            sock = new ServerSocket(port);
            System.out.println("MyServer running at port " + port);
        } catch (IOException e) {
            System.out.println("Error: couldn't create socket.");
            System.exit(1);
        }
    }

    public void run() {
        Socket client = null;

        while (true) {
            if (sock == null)
                return;
            try {
                client = sock.accept();
                // Recebendo identificacao
                BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
                String c = in.readLine();
                System.out.println(c);

                // Enviando Informacoes
                BufferedOutputStream bos = new BufferedOutputStream(client.getOutputStream());
                PrintWriter os = new PrintWriter(bos, false);
                os.println(executar(c));
                os.flush();
                os.close();
                client.close();
            } catch (IOException e) {
                System.out.println("Error: couldn't connect to client.");
                System.exit(1);
            }
        }
    }

    private String executar(String conteudo) {
        return conteudo.toLowerCase();
    }

    public static void main(String[] arguments) {
        int port = 4001;
        if (arguments.length == 1) {
            port = Integer.parseInt(arguments[0]);
        }
        MyServer2 server = new MyServer2(port);
        server.start();
    }
}
</code></pre>
