Forums » Union General »
For Java Apps
Added by Gopal Chavan 877 days ago
Hi.
I was wondering if it is possible to use Union Platform with Java applications/games ??
If so, how should I get started ??
Replies
RE: For Java Apps - Added by derek clayton 877 days ago
It's absolutely possible to use Union Platform to create Java applications. You would have two options:
1) Implement your own architecture that follows the UPC message protocol which is located at http://unionplatform.com/specs/upc/.
2) We are also developing a Java client framework called 'Mariner'. For the near future it won't be as feature rich as the flash client framework 'Reactor' but it will help you to get started developing Java clients more quickly. Mariner (mariner.jar) is actually included with the current Union Server distribution since it's used to send administration commands as used in stopserver.sh/stopserver.bat.
Support for Mariner will be limited during Alpha but here's some sample code which will help you get started.
import net.user1.mariner.MessageEvent;
import net.user1.mariner.UConnection;
import net.user1.mariner.UConnectionEvent;
public class MarinerClient {
private UConnection m_connection;
public MarinerClient(String host, int port) {
m_connection = new UConnection();
m_connection.addEventListener(UConnectionEvent.READY, this, "onConnectionReady");
System.out.println("Opening connection...");
m_connection.open(host, port);
}
public void onConnectionReady(UConnectionEvent evt) {
System.out.println("Connection established.");
m_connection.getMessageManager().addEventListener("u32", this, "onCreateRoomResults"); // listen for the message that tells me my create room results
m_connection.getMessageManager().sendUPC("u6", "myNewRoom", "", "", ""); // create a room called "myNewRoom" with default settings, no attributes, and no room modules
}
public void onCreateRoomResults(MessageEvent evt) {
System.out.println("My attempt to create room " + evt.getUPCMessage().getArgText(0) + " had a result of " + evt.getUPCMessage().getArgText(1));
}
}
I whipped this up by hand so let me know if you have any issues.
As all things in Alpha the API could be subject to significant change.
Regards,
Derek
RE: For Java Apps - Added by Gopal Chavan 876 days ago
Great.
Ya, I see "sendUPC" is in action; it would be tedious to use specific "u??" for listeners and messaging.
I hope Mariner be more easy, like Reactor.
Thanks, I'll try it.