/** Sends out an array containing information about all the connected to the ccserver */ private void sendConnectedList() { // Setup some stuff ArrayList<ConnectionThread> currentConnections = parent.getConnectionThread(); ConnectionThread tempConnection; int size = currentConnections.size(); System.out.println(" Number of users: " + size); try { // Send packageID dos.writeByte(4); // Start sending to master how many entry's we will send dos.writeInt(size); for (int i = 0; i < size; i++) { tempConnection = currentConnections.get(i); // Send id dos.writeInt(tempConnection.getccserverId()); // Send name writeString(tempConnection.getComputerName()); // Send if in used dos.writeBoolean(tempConnection.isInUse()); // Send if thread is a master dos.writeBoolean(tempConnection.isMaster()); } } catch (IOException e) { parent.log.printlnErr("IO exception from thread #" + ccserverId + "@sendConnectionList"); e.printStackTrace(); } }
/** * This will ask this thread´s client to connect to the IP This method is called from another * ConnectionThread that is a master * * @param ip IP-address to the master * @param port Port that master is listening on * @return True if the thread is not busy */ public boolean connectSlaveToMaster(String ip, int port) { // Check so that the thread is still alive and it not a master and that it not allready in use if (running && !master && !inUse) { // Set that this thread is in use inUse = true; // Now send a request to the slave to connect to the master try { // PackageID = 10 dos.writeByte(10); // Send the ip writeString(ip); // Send the port number dos.writeInt(port); } catch (IOException e) { parent.log.printlnErr("Something went wrong trying to setup input/output streams"); e.printStackTrace(); } return true; } else { return false; } }