aspose file tools*
The moose likes Java Micro Edition and the fly likes javax.microedition.io.ConnectionNotFoundException: TCP open Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "javax.microedition.io.ConnectionNotFoundException: TCP open" Watch "javax.microedition.io.ConnectionNotFoundException: TCP open" New topic
Author

javax.microedition.io.ConnectionNotFoundException: TCP open

Imdad Soomro
Greenhorn

Joined: Jul 15, 2009
Posts: 16
Hi People,
I want to make a J2ME application which accesses the servlet on server. That server fetches the data from database and sends back. My J2Me application reads that data. My application runs fine and shows the data from database when i give it a local IP in URL but when i give it a URL of live server, it throws an exception javax.microedition.io.ConnectionNotFoundException: TCP open

Could you please help me resolve this problem? Firewall are turned off. I think firewall is not problem here.

Following is the my code.

package log;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.io.*;
import java.lang.*;
import javax.microedition.io.*;
import javax.microedition.rms.*;
//import com.symbol.j2me.midlets.ascanner.BarCodeReader;

public class Login extends MIDlet implements CommandListener{
TextField UserName=null;
TextField Location=null;
Form authForm,mainscreen;
TextBox t = null;
StringBuffer b = new StringBuffer();
private Display myDisplay = null;
private Command okCommand = new Command("OK", Command.OK, 1);
private Command exitCommand = new Command("Exit", Command.EXIT, 2);
private Command backCommand = new Command("Back", Command.BACK, 2);
private Alert alert = null;



public Login() {

myDisplay = Display.getDisplay(this);

UserName=new TextField("Your Name" , "",10,TextField.ANY);
Location=new TextField("Location" , "",10,TextField.ANY);
authForm=new Form("Identification");
mainscreen=new Form("Logging in");
mainscreen.append("wait");
mainscreen.addCommand(backCommand);
authForm.append(UserName);
authForm.append(Location);
authForm.addCommand(okCommand);
authForm.addCommand(exitCommand);
authForm.setCommandListener(this);
myDisplay.setCurrent(authForm);

}

public void startApp() throws MIDletStateChangeException {
}

public void pauseApp() {

}



protected void destroyApp(boolean unconditional)
throws MIDletStateChangeException {
}


public void commandAction(Command c, Displayable d) {

if ((c == okCommand) && (d == authForm)) {
if (UserName.getString().equals("") || Location.getString().equals("")){
alert = new Alert("Error", "You should enter Username and Location", null, AlertType.ERROR);
alert.setTimeout(Alert.FOREVER);
myDisplay.setCurrent(alert);
}
else{
//myDisplay.setCurrent(mainscreen);
Thread t = new Thread() {
public void run() {
if(UserName.getString().equals("test") & Location.getString().equals("test")){
login("test","test");
}else{
Alert alt=new Alert("Error", "Invalid username or password", null, AlertType.ERROR);
alt.setTimeout(Alert.FOREVER);
myDisplay.setCurrent(alt);
}
}
};
t.start();

//login("test","test");
}
}
if ((c == backCommand) && (d == mainscreen)) {
myDisplay.setCurrent(authForm);
}
if ((c == exitCommand) && (d == authForm)) {
notifyDestroyed();
}
}

public void login(String UserName,String PassWord) {

HttpConnection connection=null;
DataInputStream in=null;

String url="http://oracle.plexushosting.com:8080/cellphone/servlet/cell";

OutputStream out=null;
try
{

connection=(HttpConnection)Connector.open(url);
connection.setRequestMethod(HttpConnection.GET);
connection.setRequestProperty("IF-Modified-Since", "8 Jul 2009 15:10:15 GMT");
connection.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.1");
connection.setRequestProperty("Content-Language", "en-US");
connection.setRequestProperty("Content-Length",""+ (UserName.length()+PassWord.length()));
connection.setRequestProperty("UserName",UserName);
connection.setRequestProperty("PassWord",PassWord);

out = connection.openDataOutputStream();
out.flush();
in = connection.openDataInputStream();

int ch;



while((ch = in.read()) != -1) {


b.append((char) ch);

//System.out.println((char)ch);
}
//t = new TextBox("Reply",b.toString(),1024,0);

mainscreen.append(b.toString());
if(in!=null)
in.close();
if(out!=null)
out.close();
if(connection!=null)
connection.close();
}
catch(IOException x){
mainscreen.append("Erorrrrrrrrrrrrrrrrr");
x.printStackTrace();
}

myDisplay.setCurrent(mainscreen);

}

}





*************************************************


If i write this URL which is local network IP, it works fine.

String url="http://192.168.1.12:8080/cellphone/servlet/cell";

Please help.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

Welcome to the JavaRanch, Imdad!

I suspect you have no route to the public host. If your device has a built-in web browser, try supplying that URL it it and see what happens. As long at the browser can access the URL, your JME app should be able to do so as well.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javax.microedition.io.ConnectionNotFoundException: TCP open