working multi client
This commit is contained in:
parent
53c846a386
commit
d4572677f5
Binary file not shown.
|
@ -10,7 +10,7 @@ class Client {
|
|||
public static void main(String[] args) {
|
||||
// establish a connection by providing host and port
|
||||
// number
|
||||
try (Socket socket = new Socket("localhost", 1234)) {
|
||||
try (Socket socket = new Socket("localhost", 8080)) {
|
||||
|
||||
// writing to server
|
||||
PrintWriter out = new PrintWriter(
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -13,8 +13,8 @@ class Server {
|
|||
Socket client = server.accept();
|
||||
System.out.println("New client: " + client.getInetAddress().getHostAddress());
|
||||
|
||||
ClientHandler clientsock = new ClientHandler(client);
|
||||
new Thread(clientSock.start());
|
||||
ClientHandler clientSock = new ClientHandler(client);
|
||||
new Thread(clientSock).start();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -31,7 +31,7 @@ class Server {
|
|||
|
||||
private static class ClientHandler implements Runnable {
|
||||
|
||||
private final Socket clientSocket;
|
||||
private Socket clientSocket;
|
||||
|
||||
public ClientHandler(Socket socket) {
|
||||
this.clientSocket = socket;
|
||||
|
@ -59,6 +59,7 @@ class Server {
|
|||
}
|
||||
if (in != null) {
|
||||
in.close();
|
||||
System.out.println("closing socket " + clientSocket.getInetAddress().getHostAddress());
|
||||
clientSocket.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
Loading…
Reference in New Issue