1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| serverSocket = null;
try {
serverSocket = new ServerSocket(7000);
serverSocket.setSoTimeout(2000);
System.out.println("Server is opened");
} catch (IOException e) {
System.out.println("Could not listen on this port");
}
clientSocket = null;
try {
clientSocket = new Socket("localhost", 7000);
clientSocket = serverSocket.accept();
clientSocket.setSoTimeout(15000);
System.out.println("Client is connected");
isClientConnected = true;
} catch (IOException e) {
System.out.println("Accept client failed");
} |
Partager