Java Reference
In-Depth Information
mTextBox.addCommand(new Command("Exit", Command.EXIT, 0));
mTextBox.addCommand(new Command("Send", Command.SCREEN, 0));
mTextBox.setCommandListener(this);
}
mDisplay.setCurrent(mTextBox);
}
public void commandAction(Command c, Displayable s) {
if (c.getCommandType() == Command.EXIT) notifyDestroyed();
else {
Form waitForm = new Form("Connecting...");
mDisplay.setCurrent(waitForm);
Thread t = new Thread(this);
t.start();
}
}
public void run() {
// Encrypt our message.
byte[] plaintext = mTextBox.getString().getBytes();
byte[] ciphertext = new byte[plaintext.length];
mOutCipher.processBytes(plaintext, 0, plaintext.length, ciphertext, 0);
char[] hexCiphertext = HexCodec.bytesToHex(ciphertext);
// Create the GET URL. Our user name and the encrypted, hex
// encoded message are included as parameters. The user name
// and base URL are retrieved as application properties.
String baseURL = getAppProperty("StealthMIDlet-URL");
URLBuilder ub = new URLBuilder(baseURL);
ub.addParameter("user", getAppProperty("StealthMIDlet.user"));
ub.addParameter("message", new String(hexCiphertext));
String url = ub.toString();
try {
// Query the server and retrieve the response.
HttpConnection hc = (HttpConnection)Connector.open(url);
if (mSession != null)
hc.setRequestProperty("cookie", mSession);
InputStream in = hc.openInputStream();
String cookie = hc.getHeaderField("Set-cookie");
if (cookie != null) {
int semicolon = cookie.indexOf(';');
mSession = cookie.substring(0, semicolon);
}
Search WWH ::




Custom Search