×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    May 2007
    Location
    dubai
    Posts
    62

    tcp open error accessing the server

    hi every body ,
    i am having a problem here and hope somebody could help.

    what i need to do is a j2me application that get data from database residing on my test server,i did the servlet and the midp application and i am using emulator to test .when i used the emulator on the server itself and connected using url="http://localhost:8080/midp/rCon"
    every thing works fine .
    the problem starts when i try to test from another pc and use url="http://80.227.99.92:8080/midp/rCon"

    i have a test server( which is i am sure its working as i tried to connect its index page and i succeeded).the root of this server is C:\inetpub\wwwroot.

    i installed tomcat in c:\inetpub\wwwroot\tomcat inorder to be able to accses my servlet(as i thought)

    my servlet class is in tomcat\webapps\midp\web-inf\classes\getconnection.class

    this is part of the code in getconnection.java file
    <code>

    public void doPost(HttpServletRequest request,
    HttpServletResponse response) throws ServletException,
    IOException {

    DataInputStream in = new DataInputStream((InputStream)request.getInputStream());

    Connection con=null;
    ResultSet ssub=null;
    Statement statement =null;
    String result="";
    String message ="test message ::";
    try {

    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    con = DriverManager.getConnection
    ("jdbc:sqlserver://mersal:1433;databaseName=test","sa","mersal");

    System.out.println(" con "+con.toString());
    statement = con.createStatement();
    ssub= statement.executeQuery("select * from tbl_shares");


    if (ssub==null){
    System.out.println("NULL RS");
    }
    else{
    System.out.println("NOT NULL RS");

    }

    try{

    while(ssub.next()){

    System.out.println("______________________________________________________________________--");
    result+=ssub.getString("EnglishName")+","+ssub.getString("Symbol")+","+ssub.getString("Opening")+","+ssub.getString("LastDayClosing")+
    ","+ssub.getString("BidRate")+","+ssub.getString("BidVolume")+","+ssub.getString("OfferRate")+","+ssub.getString("OfferVolume")+
    ","+ssub.getString("CurrRate")+","+ssub.getString("Volume")+","+ssub.getString("TotalTrade")+","+ssub.getString("HighRate")+
    ","+ssub.getString("LowRate")+","+ssub.getString("PerChange")+","+ssub.getString("LastUpdated")+","+ssub.getString("Market")+
    ","+ssub.getString("TotalValue")+","+ssub.getString("SortValue")+","+ssub.getString("AvrgRate")+","+ssub.getString("ArabicName")+
    ","+"/";

    }
    ssub.close();
    System.out.println("finish rs issue beside connect");
    }

    catch(Exception e)
    {
    System.out.println("Exception in rs "+e.getMessage());
    }
    message+="successful connection";


    //String result="iam,raghda,and,iam,testing,the,server,to,see,if,it,is,working,or,not,yes,not,yes,not,yes,/iam,raghda,and,iam,testing,the,server,to,see,if,it,is,working,or,not,yes,not,yes,not,yes,/";

    response.setContentType("text/plain");
    response.setContentLength(result.length());

    PrintWriter out = response.getWriter();
    System.out.println(result);
    out.print(result);


    statement.close();
    ssub.close();
    con.close();
    in.close();
    out.close();
    out.flush();


    }
    catch (Throwable t) {
    message += "Error in connection ";
    }


    }

    </code>


    and in midlet this is the part of code responsible for the connection

    <code>
    where 80.227.99.92 is the global ip address of my test server
    private String url ="http://80.227.99.92:8080/midp/rCon";
    public void run() {
    StringBuffer sb = new StringBuffer();
    try {

    HttpConnection c = (HttpConnection) Connector.open(url);
    System.out.println("________________________1");
    c.setRequestProperty("User-Agent","Profile/MIDP-1.0, Configuration/CLDC-1.0");
    System.out.println("________________________2");
    c.setRequestProperty("Content-Language","en-US");
    System.out.println("________________________3");
    c.setRequestMethod(HttpConnection.POST);
    System.out.println("________________________4");
    DataOutputStream os = (DataOutputStream)c.openDataOutputStream();
    System.out.println("________________________5");
    os.writeUTF(db.trim());
    System.out.println("________________________6");
    os.writeUTF(user.trim());
    System.out.println("________________________7");
    os.writeUTF(pwd.trim());
    System.out.println("________________________8");
    os.flush();
    System.out.println("________________________9");
    os.close();

    System.out.println("before input streanm");

    // Get the response from the servlet page.
    DataInputStream is =(DataInputStream)c.openDataInputStream();

    // is = c.openInputStream();
    int ch;
    sb = new StringBuffer();

    while ((ch = is.read()) != -1) {
    sb.append((char)ch);
    }

    queryResult=sb.toString();
    System.out.println("queryResult "+queryResult);
    byte[] b=queryResult.getBytes();
    is.close();
    c.close();


    } catch (Exception e) {
    //showAlert("Error Message "+e.getMessage());
    System.out.println("Error Message "+e.getMessage());
    }
    </code>


    the last lines i see in logs is
    ________________________8
    Error Message Tcp open
    so i suppose that it has a problem in os.flush()


    replies are appreciated

    and then i see the
    raghda

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Brazil
    Posts
    1,884

    Re: tcp open error accessing the server

    Hi raghda,

    May you please provide the entire stack trace for analysis? Besides, make sure you do not have firewall software preventing you from connecting.

    Br,
    Juarez Alvares Barbosa Junior - Brazil

  3. #3
    Regular Contributor
    Join Date
    May 2007
    Location
    dubai
    Posts
    62

    Re: tcp open error accessing the server

    hi jaurezjunior,
    thank you for replying to my question.
    i am sorry i didnot understand this sentence
    Quote Originally Posted by juarezjunior
    May you please provide the entire stack trace for analysis?
    Br,
    what did u mean with the entire stack??
    I really dont know so much about servers and firewall but i try to check if i am blocked or not

    Thanks
    raghda

  4. #4
    Registered User
    Join Date
    Dec 2005
    Location
    Brazil
    Posts
    1,884

    Re: tcp open error accessing the server

    Hi raghda,

    This is what I was talking about:

    Learn how to print a stack trace to debug Java exceptions
    http://www.devdaily.com/java/edu/pj/...pj010009.shtml

    An Introduction to Java Stack Traces
    http://java.sun.com/developer/techni...ng/Stacktrace/

    Kind regards,
    Juarez Alvares Barbosa Junior - Brazil

Similar Threads

  1. cannot connect to TCP server with SDK 6.1
    By cincin1977 in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2006-06-24, 18:10
  2. Programatically starting a custom server
    By GJokiel in forum Symbian
    Replies: 1
    Last Post: 2003-05-19, 10:50
  3. Please help implementing WTLS
    By Nokia_Archived in forum WAP Servers
    Replies: 1
    Last Post: 2002-05-20, 13:27

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×