import java.io.*;
import java.net.*;
    public class EchoServer {
        public static void main(String[] args){
            try{
                ServerSocket ss=new ServerSocket(1234);
                System.out.println("Opened Serversocket and waiting");
                while (true) {
                    Socket s = ss.accept();//establishes connection

                    DataInputStream dis = new DataInputStream(s.getInputStream());
                    String str = (String) dis.readUTF();   // receives from client
                    System.out.println("Received from client the message= " + str);

                    String response= "Echo "+str; //computes response for client

                    DataOutputStream dos = new DataOutputStream(s.getOutputStream());
                    dos.writeUTF(response);// sends to client
                    dos.flush();
                    dos.close();
                    System.out.println("Respose was sent to client");
                    s.close();
                }
            }catch(Exception e){System.out.println(e);}
        }
    }

