public void sendMyProxyAddress() throws IOException { outputStream = socket.getOutputStream(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); out = new BufferedWriter(outputStreamWriter); JsonObject jsonObject = new JsonObject(); jsonObject .withKeyValue("msgtype", ModelCloudProxy.class.getSimpleName()) .withKeyValue("hostName", modelCloud.getHostName()) .withKeyValue("portNo", modelCloud.getAcceptPort()); String message = jsonObject.toString(); out.write(message + "\n"); out.flush(); proxy.setState("online"); }
@Override public void propertyChange(PropertyChangeEvent evt) { if (this.socket == null && proxy.getPortNo() > 0) { try { socket = new Socket(proxy.getHostName(), proxy.getPortNo()); new ClientSocketHandler(modelCloud, socket).start(); // first send my own data sendMyProxyAddress(); } catch (IOException e) { // did not work socket = null; proxy.setState("offline"); } } }