• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

javax.microedition.io.ConnectionNotFoundException: TCP open

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic