I am currently working on a one server many clients system. I am trying to get it so the server can send out one command, through a PrintWriter, that will go through to all of the clients connected on that socket. However in practice the command only goes through to one client. All of the clients are created on one socket, and all use the same Scanner. Is what I am trying to do possible?
Some code(incase it helps)
Creation of the socket:
serverSocketRefresh = new ServerSocket(PORTREFRESH); refresh = serverSocketRefresh.accept(); Creation of the Print Writer and the Scanner: networkOutputRefresh = new PrintWriter(refresh.getOutputStream(), true); networkInput = new Scanner(refresh.getInputStream()); Ceation of the clients:
do { // Wait for client... client = serverSocket.accept(); System.out.println("\nNew client accepted.\n"); handler = new ClientHandler(client,networkOutputRefresh, itemArray, bidderArray); handler.start(); } while (true); The command im trying to transmit to all of the clients:
public static void updatePrice() { networkOutputRefresh.println("1"); }