Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   General Computer Support (http://www.velocityreviews.com/forums/f44-general-computer-support.html)
-   -   Why this application works differently in a mobile phone and an emulator? (http://www.velocityreviews.com/forums/t739515-why-this-application-works-differently-in-a-mobile-phone-and-an-emulator.html)

Confused 12-05-2010 07:28 AM

Why this application works differently in a mobile phone and an emulator?
 
I want to send a message to my computer actually connected to the internet from my mobile phone. I am able to use this program with a java emulator and it works fine however, when I deploy it on my mobile phone, it does not work ,just asks me if I want to connect to the internet and does not respond as expected..

My client codes ::


public void startApp() {
try {
// establish a socket connection with remote server
streamConnection =
(StreamConnection) Connector.open(connectString);


// create DataOuputStream on top of the socket connection
outputStream = streamConnection.openOutputStream();
dataOutputStream = new DataOutputStream(outputStream);

// send the HTTP request
dataOutputStream.writeUTF("xcxxxxVimal");
dataOutputStream.flush();

// create DataInputStream on top of the socket connection
inputStream = streamConnection.openInputStream();
dataInputStream = new DataInputStream(inputStream);
dataInputStream.available();
// retrieve the contents of the requested page from Web server
String test="";
int inputChar;
int avai= dataInputStream.available();
byte[] bt=new byte[avai];
dataInputStream.read(bt, 0, avai);
// dataInputStream.read(bt, 0, avai);
for (int t=0;t<bt.length;t++){
System.out.println((char ) bt[t]);
}

System.out.println("Leaving read...........");
// display the page contents on the phone screen
//System.out.println(" Result are "+results.toString());
System.out.println(" ");
resultField = new StringItem(null, results.toString());
System.out.println("Client says "+resultField);
resultScreen.append(resultField);
myDisplay.setCurrent(resultScreen);

} catch (IOException e) {
e.printStackTrace();
System.err.println("Exception caught:" + e);
} finally {
// free up I/O streams and close the socket connection
try {
if (dataInputStream != null)
dataInputStream.close();
} catch (Exception ignored) {}
try {
if (dataOutputStream != null)
dataOutputStream.close();
} catch (Exception ignored) {}
try {
if (outputStream != null)
outputStream.close();
} catch (Exception ignored) {}
try {
if (inputStream != null)
inputStream.close();
} catch (Exception ignored) {}
try {
if (streamConnection != null)
streamConnection.close();
} catch (Exception ignored) {}
}

}




Server codes
public static void main(String[] args) {
// TODO code application logic here
try{
ServerSocket sck=new ServerSocket(880);
Socket client=sck.accept();
InputStream inp= client.getInputStream();
int i;
OutputStream out=client.getOutputStream();
out.write("Testing \r\n".getBytes());

System.out.println("Server has responded ");
String str="";
int len=inp.available();
byte[] bu=new byte[len];
System.out.println("Length is"+len);
inp.read(bu,0,len);

for (int ii=0;ii<bu.length;ii++){
System.out.println((char)bu[ii]);
}


}
catch(Exception e){
System.out.println("Error "+e);
}

}



The above program works fine when I use it in an emulator but as I deploy it on my mobile phone, it just prompts me if I want to connect to the Network and stays idle..
Why such a difference?


All times are GMT. The time now is 12:42 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.