Sample code to make a persistent TCP connection in java

I want to create a sample TCP client-server pair. The client will take input string from console and send it to server, server will print the request string and respond back with some string. I don’t want close the connection once a transaction is done, using the same connection I want to keep on sending request and getting response from server.

I have written the following client-server code , first transaction happens correctly but when I try to send second request, nothing is received by server and client hangs. I tried to google for solution but could not find anything helpful. Please help.

Client Code

public class Client {

    public static void main( String[] args ) throws UnknownHostException, IOException {
         Socket clientSocket = new Socket( "localhost", 81 );
         DataOutputStream out = new DataOutputStream( clientSocket.getOutputStream() );
         BufferedReader in =
            new BufferedReader( new InputStreamReader( clientSocket.getInputStream() ) );
         System.out.println( "connected to server" );

         while ( true ) {
             System.out.println( "enter data to send" );
             Scanner sc = new Scanner( );
             String msg = sc.nextLine();
             out.writeBytes( msg + "n" );
             System.out.println( "response from server : "+in.readLine() );



Server Code

public class Server {

    public static void main(String args[]) throws IOException{
        ServerSocket ss = new ServerSocket(81);
        System.out.println( "server started" );
            System.out.println( "waiting for client" );
            Socket s = ss.accept();
            System.out.println( "connected to client" );
            BufferedReader in = new BufferedReader( new InputStreamReader( s.getInputStream() ) );
            DataOutputStream out = new DataOutputStream( s.getOutputStream() );
            System.out.println( "recieved: "+ in.readLine()  );
            out.writeBytes( "200n" );