i wanted to create a java server and client in a same file...because this is my structure of project
SERVER ---> CLIENT/SERVER ----> CLIENT
the coding for the SERVER and CLIENT part is quite simple but i have a problem when creating for CLIENT/SERVER part.. where my code can only run CLIENT part and not starting the SERVER part. because of my thread run() code.
package com.main.datadistributor;
import java.io.IOException;
import java.net.ServerSocket;
public class Slave {
public static void main(String args[]) throws IOException{
Config cfg = new Config("Slave");
String MasterServerIP = cfg.getProperty("MasterServerIP");
String MasterServerPort = cfg.getProperty("MasterServerPort");
String SlaveServerPort = cfg.getProperty("SlaveServerPort");
Client client = new Client(MasterServerIP,Integer.parseInt(MasterServerPort),"SLAVEONE");
client.run();
int numClient = 0;
ServerSocket listener = new ServerSocket(Integer.parseInt(SlaveServerPort));
System.out.println("Server starts running");
try{
while(true){
new Server(listener.accept(), numClient++, Integer.parseInt(SlaveServerPort), "SLAVESERVER").start();
}
} finally {
listener.close();
}
}
}
from the code above i have problem only executing client.run() and the code just stop there without proceeding to execute new Server below at the try section