private void initialHandshake() throws EOFException { String userName = session.getUserID().getUsername(); int strLen = userName.length(); // Inform the server that we have connected by sending a hello message // with the name of this user byte[] helloBuf = new byte[Proto.ClientMessageType.HELLO.size() + strLen + Proto.SIGNATURE_SIZE]; helloBuf[0] = (byte) Proto.ClientMessageType.HELLO.ordinal(); helloBuf[1] = (byte) 0; // pad helloBuf[2] = (byte) ((strLen >> 8) & 0xff); helloBuf[3] = (byte) (strLen & 0xff); System.arraycopy(userName.getBytes(), 0, helloBuf, 4, strLen); try { slaveSocket.send(sign(helloBuf)); } catch (IOException ex) { throw new RuntimeException(ex); } AppXrw.logger.info("Broadcast slave Hello message for user " + userName); // Get the welcome message from the server. This contains the client id // Note: because the master hub broadcasts to all slaves, there is a chance // there might be irrelevant messages queued up for this // slave. These should be ignored. This come from the fact that it takes // some time after the slave joins the connection for the master to become // aware of it and to compose and send the welcome message. During this time // if there are any incoming messages from the X server they will be // forwarded to this slave even if it has not yet been officially welcomed. // Since the content of these messages will be reflected in the welcome message // and the slave can't really do anything until it is welcomed we need // to ignore these messages. ServerMessageType type = null; do { type = getMessageType(); } while (type != ServerMessageType.WELCOME); // TODO: eventually we should add a timeout // Skip 3 bytes of pad bufQueue.nextByte(); bufQueue.nextShort(); clientId = bufQueue.nextInt(); client.setClientId(clientId); windowParents.clear(); // Read the initial window state synchronization // part of the welcome message int numWins = bufQueue.nextInt(); AppXrw.logger.info("numWins = " + numWins); for (int i = 0; i < numWins; i++) { syncWindowStateNext(); } // All windows have been defined. Now assign the parents for (WindowXrw win : windowParents.keySet()) { Integer parentWid = windowParents.get(win); if (parentWid != null) { WindowXrw parentWin = client.lookupWindow(parentWid.intValue()); win.setParent(parentWin); } } windowParents.clear(); client.updateSlaveWindows(); }