Anatomy of a Network Communication Lifecycle
Let's look at an example from the documentation:
@Action public void doGetVersionInfoAction() { try {
/* Instantiate our NetworkCommuniation class.
*NOTE: Both the request and the response are NetworkCommunication objects */
NetworkCommunication incomm = new NetworkCommunication();
/* Instantiate the NetworkAction. This class tells the server what to do
with the parameters passed, and holds the uuid you'll want to retrieve
later.
*/
NetworkAction action = new NetworkAction();
/* Set the ActionType.
In this case, we're requesting the server info
Available Action Types from NetworkAction:public enum ActionType { SEARCH, LOGON, CHANGE_ENCRYPTION, SEND_MESSAGE, SEND_FILE, REQUEST_FILE, MESSAGE_RECEIVED, SERVER_INFO, PING, QUERY; }Read more about the NetworkAction.ActionType*/
action.setAction(NetworkAction.ActionType.SERVER_INFO);
// create a handle so you can get the NetworkMessage back from the response.
String uuid = UUID.genUUID();
/* set the UUID.
**Hint: VERY IMPORTANT ** You'll still get a response, but you won't know which NetworkMessage object returned (there can be more than one) matches up to this particular action. You can send more than one action. */
action.setUuid(uuid);
// Add the NetworkAction. You can have multiple Actions.
incomm.addMessage(action);
// Send the request via the NetworkManager.
NetworkCommunication respc = NetworkManager.send(incomm);
/* parse the response. Null check is for redundancy, or a fatal state. generally, the server will always respond. */
if (respc != null) {
// get the response using our uuid above
NetworkResponse resp = (NetworkResponse) respc.getMessageByUuid(uuid);
// get the data, already decrypted!
String data = resp.getContent();
// spin up the response into an XML document.
Document doc = XMLHelper.parseDocumentFromString(data);
// log the result.
Log.logToWindow(getClass(), doc.getRootElement().getText()); } else { Log.logToWindow(getClass(), "Response was null"); } } catch (Exception e) { e.printStackTrace(); } }
So you can see that it's pretty easy to spin up a request. Nothing fancy. Just add your data and go! Aedon is built around flexibility and scalabity. Why spend hours pouring over docs just to be able to use someone's server? With Aedon, it's quick and easy. |