|
@@ -1,4 +1,32 @@ |
|
|
package xyz.nextn; |
|
|
package xyz.nextn; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
import java.io.PrintWriter; |
|
|
|
|
|
import java.net.ServerSocket; |
|
|
|
|
|
import java.net.Socket; |
|
|
|
|
|
|
|
|
public class Server { |
|
|
public class Server { |
|
|
|
|
|
private ServerSocket serverSocket; |
|
|
|
|
|
|
|
|
|
|
|
public void start(int port) throws IOException { |
|
|
|
|
|
serverSocket = new ServerSocket(port); |
|
|
|
|
|
while (true) |
|
|
|
|
|
new EchoClientHandler(serverSocket.accept()).start(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void stop() throws IOException { |
|
|
|
|
|
serverSocket.close(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static class EchoClientHandler extends Thread { |
|
|
|
|
|
private Socket clientSocket; |
|
|
|
|
|
private PrintWriter out; |
|
|
|
|
|
private BufferedReader in; |
|
|
|
|
|
|
|
|
|
|
|
public EchoClientHandler(Socket socket) { |
|
|
|
|
|
this.clientSocket = socket; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |