0% found this document useful (0 votes)
3 views2 pages

Java Server Client Short

The document provides a simple implementation of a multi-client server in Java using sockets. The server listens on port 5000 and spawns a new thread for each client connection to handle incoming messages. The client connects to the server, sends messages, and prints the server's responses.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Java Server Client Short

The document provides a simple implementation of a multi-client server in Java using sockets. The server listens on port 5000 and spawns a new thread for each client connection to handle incoming messages. The client connects to the server, sends messages, and prints the server's responses.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Java Multi-Client Server (Short &

Correct Version)
Server
import [Link].*;
import [Link].*;

public class Server {


public static void main(String[] args) throws Exception {
ServerSocket ss = new ServerSocket(5000);

while (true) {
Socket s = [Link]();

new Thread(() -> {


try {
BufferedReader in = new BufferedReader(
new InputStreamReader([Link]()));
PrintWriter out = new PrintWriter(
[Link](), true);

String msg;
while ((msg = [Link]()) != null) {
[Link](msg);
[Link](msg);
}
} catch (Exception e) {}
}).start();
}
}
}

Client
import [Link].*;
import [Link].*;

public class Client {


public static void main(String[] args) throws Exception {
Socket s = new Socket("localhost", 5000);

BufferedReader in = new BufferedReader(


new InputStreamReader([Link]()));
PrintWriter out = new PrintWriter(
[Link](), true);

BufferedReader k = new BufferedReader(


new InputStreamReader([Link]));

String msg;
while ((msg = [Link]()) != null) {
[Link](msg);
[Link]([Link]());
}
}
}

You might also like