How to push transactions dynamically into the run method of the hash graph?
For instance: In the below code, the name is published as a transaction. How to get this value dynamically. If it has to be through a socket, which is the best place to initiate the socket?
public void run() {
String myName = platform.getState().getAddressBookCopy().getAddress(selfId).getSelfName();
console.out.println("Hello Swirld from " + myName);
byte[] transaction = myName.getBytes(StandardCharsets.UTF_8);
platform.createTransaction(transaction, null);
String lastReceived = "";
while (true) {
IPOSAppState state = (IPOSAppState) platform.getState();
String received = state.getReceived();
if (!lastReceived.equals(received)) {
lastReceived = received;
console.out.println("Received: " + received); // print all received transactions
}
try {
Thread.sleep(sleepPeriod);
} catch (Exception e) {
}
}
}
Any example code would really help.