×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    7

    Thumbs down Connection problem with Nokia 6681.

    Hi,
    I developed a http client-server application which sends some data and getting some responses from the server. I tested my application with Nokia 6681 and am getting a weird problem with that device only. It is sending the data and getting the response code as 200 but no data is getting from the stream. The length is always -1 but server is sending the data.
    I tested same Jar and Jad(I didn't even change a single line) with Nokia N70 and Sony K600, W550 and it is working fine. Am attaching the connection code with this. If somebody can find out any problem with this please help me.

    os.write(encryptedSendingData); //writing to output stream
    os.flush();

    rc = c.getResponseCode();
    myDebuger.append("in PstToDo: RC is ="+rc);

    if (rc != HttpConnection.HTTP_OK) {
    statusId=ServerErrorStatus;
    throw new IOException("HTTP response code: " + rc);
    }

    is = c.openInputStream();
    int len = (int) c.getLength();

    if(len > 0)
    {
    serverData = new byte[len];
    is.read(serverData);
    }
    else
    {
    data = new StringBuffer();
    int ch;

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

    But am not getting anything from server for Nokia 6681 and for other devices it is working fine. I stuck with this problem now and please help me. Thanks in advance..

    Regards,
    Hadhi.

  2. #2
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: Connection problem with Nokia 6681.

    hi Hadhi,

    reboot phone, removing battery when being-off to clear network data in device,
    are you using the same sim card then on other phones?

    regards,
    peter

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    7

    Re: Connection problem with Nokia 6681.

    Hi Peter,
    Thanks for your reply. The application is not getting hanged but not getting any data through GPRS. I tested the application by removing battery and all but no way. I
    I tested same application with same SIM and same builds and is working fine on other devices.
    Even before one month i noticed the same problem with this same device when one trainee did a small program in which he is getting a simple string data as "status=success" from the server. That application also worked well with other devices.
    So if somebody got any idea about this issue, please help me..

    Regards,
    Hadhi.

  4. #4
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: Connection problem with Nokia 6681.

    hi Hadhi,

    have you tested any other midlet which uses http connections on that device? (sun wtk samples/nokia samples)

    regards,
    Peter

  5. #5
    Regular Contributor
    Join Date
    Nov 2005
    Posts
    67

    Re: Connection problem with Nokia 6681.

    Hi hadhi631
    Have you launched a new thread for you http routine ?
    You should launch new theread for http routine.
    The piece of code that you show on the page is not
    enough to see that how you have arrenged the order
    of communication objects. At least you should
    check that objects you launch are not null !
    And when you flush something, you should also
    close object after flushing object and set
    object to null state.

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    7

    Re: Connection problem with Nokia 6681.

    Hi Peter,
    Thanks for your reply.

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    7

    Re: Connection problem with Nokia 6681.

    Hi Peter,
    Thanks for your reply. Yes, i've tested another MIDlet with this same phone but i got the same error. Even that MIDlet worked fine with other devices like Sony K600 and W550.

    Hi Turnabull2,
    Am doing all connection part in seperate threads. and same builds working fine on a number of other devices also. Am attaching all my connection code here. Please check it.

    String postData(String url) throws IOException
    {
    myDebuger.append(" in postData\n");
    HttpConnection c = null;
    InputStream is = null;
    OutputStream os = null;

    byte[] serverData = null;
    StringBuffer data = null;
    int rc;
    try
    {
    c = (HttpConnection) Connector.open(url);

    // Set the request method and headers
    c.setRequestMethod(HttpConnection.POST);
    c.setRequestProperty("If-Modified-Since","29 Oct 1999 19:43:31 GMT");
    c.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.0");
    c.setRequestProperty("Accept", "text/html");
    c.setRequestProperty("Content-Language", "en-US");
    c.setRequestProperty("Connection", "close");

    os = c.openOutputStream();

    os.write(encryptedSendingData); //writing to output stream
    os.flush();

    rc = c.getResponseCode();
    myDebuger.append("in PstToDo: RC is ="+rc);

    if (rc != HttpConnection.HTTP_OK) {
    statusId=ServerErrorStatus;
    throw new IOException("HTTP response code: " + rc);
    }

    is = c.openInputStream();
    int len = (int) c.getLength();

    if(len > 0)
    {
    serverData = new byte[len];
    is.read(serverData);
    }
    else
    {
    data = new StringBuffer();
    int ch;

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

    Am getting length as zero(int len = (int) c.getLength() so it will come to the else part. But there also
    while( (ch = is.read()) != -1)
    {
    data.append((char)ch);
    }
    this part is not getting anything from the input stream.

    I tried to wrap the inputstream with dataInputStream and read it, but same result. I am totally get stucked with this weired problem and please help me.

    Best regards,
    Hadhi.

  8. #8
    Regular Contributor
    Join Date
    Nov 2005
    Posts
    67

    Re: Connection problem with Nokia 6681.

    Hi hadhi631

    First of all, i can see from your code that you do not
    check your HttpConnection (c) state after instantiating
    it !

    // Yuor code
    c = (HttpConnection) Connector.open(url);

    Now you have to check that c is not null :

    if ( c == null )
    throw ...

    You have to check the state of c before going funrther
    in your code !!

    Same thing with os.
    Always check the state of created NETWORK OBJECT
    before using it !

    /////

    BTW. I have used http only with the GET-method !
    ( Nokia 6680 )
    There may be problems with POST-method - who knows.

    /////

    Here sample for you how i use GET-method routine that is
    runned in separate thread that is launched from
    UI. Note the catch blocks how they implement
    closing and nulling the objects in case when
    routine is done ok and when the routine failed.


    Sample :

    private void queryRemoteLuckyNumbers() throws IOException, Exception
    {
    HttpConnection conn = null;
    InputStream in = null;
    String url = "http://127.0.0.1:8080/turnabull/servlet/LottoServletPI";
    int contentLength = -1;

    errorMessage = null;
    serverMessage = null;

    try
    {
    if ( serverUrl.length() > 0 )
    {
    url = serverUrl;
    //System.out.println( "URL CHANGED to " + serverUrl );
    }

    //System.out.println( url + clientMessageID + clientMessage );
    conn = null;
    in = null;

    conn = (HttpConnection)Connector.open( url + clientMessageID + clientMessage );
    if ( conn == null )
    throw new Exception( "conn is null" );

    conn.setRequestMethod( HttpConnection.GET );

    in = conn.openInputStream();
    if ( in == null )
    throw new Exception( "input stream is null" );

    contentLength = (int)conn.getLength();
    byte[] rawMessage= new byte[contentLength];
    int length = in.read(rawMessage);

    serverMessage = null;
    serverMessage = new String( rawMessage, 0, length );

    in.close();
    conn.close();

    conn = null;
    in = null;

    rawMessage = null;

    //System.out.println( "*** Server message " + serverMessage );

    }
    catch( IOException ex )
    {
    //System.out.println( "IOException " + ex.getMessage() );
    errorMessage = ex.getMessage();

    if ( in != null )
    {
    in.close();
    in = null;
    }
    if ( conn != null )
    {
    conn.close();
    conn = null;
    }
    throw ex;
    }
    catch( Exception ex )
    {
    if ( in != null )
    {
    in.close();
    in = null;
    }
    if ( conn != null )
    {
    conn.close();
    conn = null;
    }

    if ( ex.getMessage() == null )
    {
    errorMessage = "null ptr with connect";
    throw new Exception( errorMessage );
    }

    //System.out.println( "Ex throwed" + errorMessage );
    throw ex;
    }

    }

  9. #9
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: Connection problem with Nokia 6681.

    Quote Originally Posted by hadhi631
    Yes, i've tested another MIDlet with this same phone but i got the same error. Even that MIDlet worked fine with other devices like Sony K600 and W550.
    hi Hadhi,

    that rather seems to be issue with our device access point (services) configuration, can you request service configuration settings from your provider (e.g. via web page request) to be sure that your device is configured correctly?
    I own 6680 which is "nearly" the same as 6681 and haven't had any issues with tcp/ip protocols yet using configuration obtained from service carrier,

    also try to not using flush(), simply write data to buffer and call getResponseCode(),

    also check headers you've sent in server logs (if any) and check headers from response you're receiving on device,
    here is sample code to read all headers from responce on device:
    http://discussion.forum.nokia.com/fo...5&postcount=15

    hth,
    regards,
    Peter

Similar Threads

  1. Nokia N-Series Complete Model Line-Up
    By Dopod in forum General Development Questions
    Replies: 6
    Last Post: 2008-07-22, 20:16
  2. nokia 3200 connection lost problem
    By ghanshyam joshi in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2004-06-15, 00:16
  3. Replies: 0
    Last Post: 2002-11-03, 23:22

Posting Permissions

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