@@ -0,0 +1,2552 @@
+package learn_to_code.java_api.net.local_multiple_times_one_connection;%0D%0A%0D%0Aimport learn_to_code.java_api.net.local_one_time_one_connection.SimpleNetworkProtocol;%0D%0A%0D%0Aimport java.io.BufferedReader;%0D%0Aimport java.io.IOException;%0D%0Aimport java.io.InputStreamReader;%0D%0Aimport java.io.PrintWriter;%0D%0Aimport java.net.ServerSocket;%0D%0Aimport java.net.Socket;%0D%0A%0D%0A/**%0D%0A * This server will open port 10000 on your machine (Can be changed obviously), accept a SINGLE connection but do not shutdown%0D%0A * after the first connection ends. If multiple clients try to connect simultaneously, they will be blocked,%0D%0A * because a client connection cannot proceed unless the server makes a call to accept() method%0D%0A * %3Cbr%3E%0D%0A * The communication is defined by %7B@link SimpleNetworkProtocol%7D class%0D%0A * Client can be %7B@link learn_to_code.java_api.net.local_one_time_one_connection.SingleConnectionLocalClient%7D%0D%0A */%0D%0Apublic class SingleConnectionNoShutdownLocalServer %7B%0D%0A    public static void main(String%5B%5D args) throws IOException %7B%0D%0A%0D%0A        try (ServerSocket serverSocket = new ServerSocket(10000)) %7B%0D%0A            while (true) %7B%0D%0A%0D%0A                /* This call will block, until first user finishes his requests, after this,%0D%0A                 * server will return to waiting state and wait for another user.%0D%0A                 * The only way to shutdown this server is to kill JVM where it is running.%0D%0A                 * Most of the time, you'll need to implement a better way to shutdown server%0D%0A                 * something like polling on server-shutdown signal once in a while%0D%0A                 */%0D%0A                createAndKeepConnection(serverSocket);%0D%0A%0D%0A            %7D%0D%0A        %7D%0D%0A    %7D%0D%0A%0D%0A    private static void createAndKeepConnection(ServerSocket serverSocket) %7B%0D%0A        try (%0D%0A                Socket clientSocket = serverSocket.accept();%0D%0A                PrintWriter toClient =%0D%0A                        new PrintWriter(clientSocket.getOutputStream(), true);%0D%0A                BufferedReader fromClient = new BufferedReader(%0D%0A                        new InputStreamReader(clientSocket.getInputStream()));%0D%0A        ) %7B%0D%0A            SimpleNetworkProtocol protocol = new SimpleNetworkProtocol(fromClient, toClient);%0D%0A%0D%0A            protocol.initialMessage();%0D%0A            /* This call will not return unless user ends connection with 'bye' response */%0D%0A            protocol.proceedData();%0D%0A            protocol.lastMessage();%0D%0A%0D%0A        %7D catch (IOException e) %7B%0D%0A            System.out.println(%22Connection error!%22);%0D%0A            e.printStackTrace();%0D%0A        %7D%0D%0A    %7D%0D%0A%7D%0D%0A

Add local server-client over socket example where server does not shutdown instantly, when the connection ends