Commit 82bf7bbe authored by 9731050's avatar 9731050

server completed

parent acfe0296
Pipeline #685 canceled with stages
import java.io.IOException; import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.net.SocketTimeoutException;
import java.util.ArrayList; import java.util.ArrayList;
public class Server { public class Server {
private static final int PORT = 4321; private static final int PORT = 4321;
private ServerSocket serverSocket; private ServerSocket serverSocket;
private ArrayList<String>user; private ArrayList<String> user;
public Server() throws Exception {
public Server() throws IOException {
serverSocket = new ServerSocket(PORT); serverSocket = new ServerSocket(PORT);
user=new ArrayList<>(); user = new ArrayList<>();
serverSocket.setSoTimeout(1000);
}
public void run() {
while (true) { while (true) {
Socket client = serverSocket.accept(); try {
ClientHandler clientHandler = new ClientHandler(client); System.out.println("Waiting for client on port " +
serverSocket.getLocalPort() + "...");
Socket client = serverSocket.accept();
ClientHandler clientHandler = new ClientHandler(client);
client.close();
} catch (SocketTimeoutException s) {
System.out.println("Socket timed out!");
break;
} catch (IOException e) {
e.printStackTrace();
break;
} catch (Exception e) {
e.printStackTrace();
}
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment