Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User surajdeo's Avatar
    Join Date
    Apr 2003
    Location
    India
    Posts
    1
    Hi,

    I am writing a MIPD 1.0 program for client side, using StreamConnection, which will communicate with a server. Server may send data at any time, for that purpose I wrote a method getMessage(), with help of Timer class which calls the getMessage() method every 1000 milli seconds. While calling the getMessage() method, if the server sends data, then it is working other wise it is blocking the whole system(i.e if no data has been sent when the getMesaage method is called). Here is the code of getMessage() method:

    public String getMessage()
    {
    String str = "";
    try
    {
    inputStream = streamConnection.openDataInputStream();
    int ch;
    while (true)
    {
    ch = inputStream.read();
    b1.append((char) ch);
    if(ch == 10) break;
    }
    str = b1.toString();
    System.out.println("From Server : " + str);
    b1 = b1.delete(0,b1.length());
    }
    catch(Exception e)
    {
    System.out.println("Error in receiving message : " + e);
    }
    return str;
    }


    Is there any way to read data from the server without blocking the system. At any time the client can send data to the server also.


    I tried using the available() method, but in all cases it is returning 0.


    - Suraj Deo

  2. #2
    Super Contributor shmoove's Avatar
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    I've had the same problem on some phones too. The available() in InputStream and getLength() from the Connection were giving wrong values on the phone (worked well on emulators). In the end I decided not to bang my head against the wall, and just worked around it by never sending empty responses from the server. Even if there is nothing to send I send some dummy data so the phones won't hang...

    shmoove

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved