Issam Tang

Greenhorn
+ Follow
since Apr 16, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Issam Tang

ok guys I solved the problem by creating the connection mechanism in a sperate thread...but now my server is not getting any requests from the client
I have both client running as part of a mobile aplication in Netbeans..and the server created as a tom cat web applications using netbeans too....I run the server first, take its address which is in my case
String url = "http://localhost:8084/Stealth_Server/";
HttpConnection hc = (HttpConnection)Connector.open(url);

so no communication happening....any hints about my problem ? ..

thanks..
18 years ago
thanks man for ur reply.....well yah this warning appears all the time.
I dont have any error message...but simply after I press Yes or No, nothing happens, I dont get any messages back or even an error. I have my server running at the same machine and no requests recived from the client. so basically after pressing yes the client doesnt send anything. and that aittime charging message doesnt go away.

really stuck on this thing for more than a week...

I hope somebody faced this so he/she can help...
18 years ago
hello ,
I am stuck on this problem for a while I searched the net and couldnt find a solution....I am creating a simple Medlet client and a webserver via Netbeans. anyways the problem is when I try to connect to my server URL which is on the same machine. I get a warning first saying
" Warning: To avoid potential deadlock, operations that may block, such as
networking, should be performed in a different thread than the
commandAction() handler."

well like u see my Client Medlet I have the connection in a sperete function (look below)
anyways when I run the client and once it calls :
HttpConnection hc = (HttpConnection)Connector.open(url);

I get a wierd question in the gui interface saying "Client want to send and recieve data using the network. This use you airtime and may result in charges.

is it OK to user airtime? "

so I press yes ofcourse , nothing happens...

I tried even using the http connection example used in netbeans and it gives me the same error...

any help is much appreciated..... ...

import java.io.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

import org.bouncycastle.crypto.StreamCipher;
import org.bouncycastle.crypto.engines.RC4Engine;
import org.bouncycastle.crypto.params.KeyParameter;
public class StealthMIDlet extends MIDlet {
private Display mDisplay;
private TextBox mTextBox;
private String mSession;
private StreamCipher mOutCipher, mInCipher;
public StealthMIDlet() {
mOutCipher = new RC4Engine();
mInCipher = new RC4Engine();
}
public void startApp() {
if (mSession == null) {
// Load the keys from resource files.
byte[] inKey = getInKey();
byte[] outKey = getOutKey();
// Initialize the ciphers.
mOutCipher.init(true, new KeyParameter(outKey));
mInCipher.init(false, new KeyParameter(inKey));
}
mDisplay = Display.getDisplay(this);
if (mTextBox == null) {
mTextBox = new TextBox("StealthMIDlet", "The eagle has landed", 256, 0);
mTextBox.addCommand(new Command("Exit", Command.EXIT, 0));
mTextBox.addCommand(new Command("Send", Command.SCREEN, 0));
mTextBox.setCommandListener(new CommandListener() {
public void commandAction(Command c, Displayable s) {
if (c.getCommandType() == Command.EXIT) notifyDestroyed();
else send();
}
});
}
mDisplay.setCurrent(mTextBox);
}

private void send() {
// 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.baseURL");
String baseURL = "http://localhost:8084/Stealth_Server/";
URLBuilder ub = new URLBuilder(baseURL);
ub.addParameter("user", getAppProperty("StealthMIDlet.user"));
ub.addParameter("message", new String(hexCiphertext));
//String url = ub.toString();
String url = "http://www.yahoo.com/";
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);
}
int length = (int)hc.getLength();
ciphertext = new byte[length];
in.read(ciphertext);
in.close();
hc.close();
}
catch (IOException ioe) {
Alert a = new Alert("Exception", ioe.toString(), null, null);
a.setTimeout(Alert.FOREVER);
mDisplay.setCurrent(a, mTextBox);
}

// Decrypt the server response.
String hex = new String(ciphertext);
byte[] dehexed = HexCodec.hexToBytes(hex.toCharArray());
byte[] deciphered = new byte[dehexed.length];
mInCipher.processBytes(dehexed, 0, dehexed.length, deciphered, 0);
String decipheredString = new String(deciphered);
Alert a = new Alert("Response", decipheredString, null, null);
a.setTimeout(Alert.FOREVER);
mDisplay.setCurrent(a, mTextBox);
}
// Normally you would probably read keys from resource files
// in the MIDlet suite JAR, using the getResourceAsStream()
// method in Class. Here I just use hardcoded values that match
// the hardcoded values in StealthServlet.
private byte[] getInKey() {
return "Incoming MIDlet key".getBytes();
}
private byte[] getOutKey() {
return "Outgoing MIDlet key".getBytes();
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
}
18 years ago