I need to make following server in to MultiClient. I'm new in JAVA, so I can not figure it out. I don't even know if it's possible to make it in any easy way, because I tried to look for any possible information or help and I failed, so, if it's not too complicated, if anyone can help to me?
This server is not written by me, I took it from JAVA SUN page.
Natesan Prabhakaran
Ranch Hand
Joined: Jul 11, 2006
Posts: 47
posted
0
Hi karl, the below program will help you much.
Server:
public class TCPServer{
private ServerSocket server;
private int port = 7777;
public TCPServer() {
try {
server = new ServerSocket(port);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
TCPServer example = new TCPServer();
example.handleConnection();
}
public void handleConnection() {
System.out.println("Waiting for client message...");
while (true) {
try {
Socket socket = server.accept();
ConnectionHandler cd = new ConnectionHandler(socket);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public class TCPClient {
public static Socket clientSocket = null;
public static PrintWriter out = null;
public static BufferedReader in = null;
public static int port=0;
static InetAddress mcAddress=null;
public static void main(String[] args) {
try
{
mcAddress = InetAddress.getByName("228.1.2.3");
port = Integer.parseInt("7777");
clientSocket = new Socket("localhost", port);
out = new PrintWriter(clientSocket.getOutputStream(), true);