All pastes #330142 Raw Edit

Something

public java v1 · immutable
#330142 ·published 2007-01-27 15:00 UTC
rendered paste body
import java.net.*;import java.io.*;public class KnockKnockServer {    public static void main(String[] args) throws IOException {                ServerSocket serverSocket = null;        try {            serverSocket = new ServerSocket(4444);        } catch (IOException e) {            System.err.println("Could not listen on port: 4444.");            System.exit(1);        }                Socket clientSocket = null;        try {            clientSocket = serverSocket.accept();        } catch (IOException e) {            System.err.println("Accept failed.");            System.exit(1);        }                PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);        BufferedReader in = new BufferedReader(                new InputStreamReader(                clientSocket.getInputStream()));        String inputLine, outputLine;        KnockKnockProtocol kkp = new KnockKnockProtocol();                outputLine = kkp.processInput(null);        out.println(outputLine);                        try {                                    while ((inputLine = in.readLine()) != null) {                outputLine = kkp.processInput(inputLine);                //out.println(outputLine);            }                    } catch (IOException e) {            System.err.println("Connection closed by client.");        } finally  {                        out.close();            in.close();            clientSocket.close();            serverSocket.close();        }                    }}