浏览代码

added Server methods

master
MrTob 5 年前
父节点
当前提交
772fd35979
共有 1 个文件被更改,包括 28 次插入0 次删除
  1. +28
    -0
      src/xyz/nextn/Server.java

+ 28
- 0
src/xyz/nextn/Server.java 查看文件

@@ -1,4 +1,32 @@
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 {
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;
}
}

}

正在加载...
取消
保存