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