Java Reference
In-Depth Information
private Console console;
private int gameClassID = 49152;
private Session smSession;
private String username = "test1";
private String password = "test";
public void startApp() {
console = new Console();
// Make the JAD file parameters accessible
Parameters.setInstance(new MIDletParameterAdapter(this));
console.println("Sending login.", Console.GREEN);
SMClient smClient = null;
try {
smClient = new SMClient(new EventListener());
console.println("login info:" + username + ":" + password,
smClient.loginSingleSignon(username, password, null, null,
gameClassID, null, 0, null, 0, false, null);
} catch (Exception e) {
// omitted code for brevity
class EventListener extends SnapEventListenerAdapter {
public void loginSingleSignonSuccess(Session session,
Friend[] friendslist, Message[] motd) {
console.println("Login successful.", Console.GREEN);
smSession = session;
console.println("Sending echo...", Console.GREEN);
// send an echo
smSession.echo(10, "HelloWorld!");
} public void echoReceived(String message) {
console.println("EchoReceived:" + message, Console.WHITE);
console.println("HelloWorld client done!", Console.GREEN);
} public void errorReceived(int code, boolean mustReturnToMainMenu) {
console.println("Error received with code"
+ code, Console.RED);
if (mustReturnToMainMenu) {
console.println("Please return to main menu.", Console.RED);
// HelloWorld
Some of the class members are used in most of the examples, as
they provide standard functionality needed to perform SNAP Mobile
operations and display results:
Console console : a utility console to display text information
being sent to or received from the server
int gameClassID : the unique game ID in the game server that
identifies requests and responses as belonging to this game, so the
server knows where to send packets requested by the game; a game
Search WWH ::

Custom Search