×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    16

    Socket read on Nokia 6600 blocks forever

    The socket inputstream functions read(byte[] b) and read(byte[] b, int offset, int len) functions should return after reading few bytes whenever they are available.
    ***Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer. ***

    But when I run this app on Nokia 6600, the app gets hang. Basically its get blocked on read() as am passing a big buffer. Then I realized it doesn't return until len bytes are read or buffer if full. So if I don't know the len of message to be read, I have to read byte by byte which consumes too much processor time.

    Anybody realized/faced this problem? I couldn't run it on any other device as my App uses MIDP2.0 APIs.

    Any idea what's going wrong?

    -DS

  2. #2
    Registered User
    Join Date
    Oct 2004
    Posts
    3

    Firmware 4.09.1 Problem

    I have the same problem. But only with Firmware 4.09.1. With 3.42.1 the funktion work correct.
    A workaround you find here
    http://www.symbian.com/developer/techlib/tips/java.html

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    16

    read() is implemented as readFully() in Nokia 6600

    Thanx Strzalla!!
    I have Firmware 4.09.1 on my 6600. How I can get Firmware 3.42.1 on it?

    The Known issues in Nokia 6600 document says that read(byte[] b) and read(byte[] b, int offset, int len) doesn't guarantee that specified size of data will be read. I am fine with it, but my problem is it doesn't return until it reads len size or until buffer if full.

    I am reading from inputstream in loop only to make sure I read the complete buffer. But since my buffer size is bigger than actual data sent from other side, the read never returns and keep waiting for buffer to be full.

    This is what am doing -
    //CHUNK_SIZE=1500
    //inputBuffer is big buffer (5000 bytes) to store socket read data
    //buffer is 1500 bytes buffer
    while (true)
    {
    bytes = socketInputStream.read(buffer, 0, CHUNK_SIZE);
    bytesRead += bytes;
    inputBuffer.write(buffer, bytesRead, bytes);
    if (bytes == -1 || GotEndOfHeader(buffer))
    {
    break;
    }
    }
    socketInputStream.close();

    Problem:
    The data size to be read from socket is not known and end of packet is indetified by marker [similiar to end of header ("\r\n\r\n")marker for http] So I read in 1500 chunk size
    Problem comes when other side sents only 200 bytes. The read in this case never returns and keep waiting till it read CHUNK_SIZE data, which server is never going to send. So it blocks forever.

    As per documentation, the read should return with some bytes as soon as they are available on socket. It shud return either 200 bytes or anything less than 200. But it just keep waiting until CHNUK_SIZE ia available on socket.

    THIS MEANS read() IS IMPLEMENTED AS readFully() ON NOKIA 66600 MIDP IMPLEMENTATION.

  4. #4
    Regular Contributor
    Join Date
    May 2003
    Posts
    471
    Hi,

    Just a thought: Maybe the proper way to send data is first by sending the length. then use a for loop to small chunks. If you will query the size of the device's socket's buffer ( maybe 64K? ) you will get much better preformance and other threads can work as well.

    nmnir.

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    16

    read() or readFully() in Nokia 600 MIDP2.0

    I know the best thing is to send size in first few bytes of data. But it works fine when your protocol has fixed size header. In my case the header size is not fixed and end of header is determined by a marker "\r\n\r\n". And this is the case for HTTP and SIP protocols. Mostly you will find end of header marker in text based protocols. The header though contains Content length, which specifies the size of body.

    But reading header is giving pain as I have to read byte by byte and check if end of header is read. It would have been good if I can read it in one go (in a big buffer) and then parse the buffer to find end of header.

    My question is Have anybody also realized that MIDP2.0 on Nokia 6600 has implemented socket read() as readFully()? Though the documentation says that it supports only read() and readFully() is not supported, but internally the read() behaves like readFully().

    Thanks

  6. #6
    Registered User
    Join Date
    Oct 2004
    Posts
    3

    Update

    The next version of Firmware is 5.27.0.
    I have this version on my Mobil.
    It's the same Problem like 4.09.

  7. #7
    Regular Contributor
    Join Date
    Jan 2004
    Posts
    165
    Keep in mind that you can get the length of the data being sent by using.

    contentLength = (int)http_connection.getLength();

    You can then use this to allocate memory, and use readFully(), or read( byte[], int, int) to get the data.

    You will need to make sure that your server end sets the header for content-length but this is simple enough.

    With PHP this is achieved by...

    header("Content-Length: $fsize");

    Where $fsize is the size of the data that will be transmitted.

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    16
    I am not using http connection but socket connection.

  9. #9
    Registered User
    Join Date
    Sep 2007
    Posts
    9

    Re: Socket read on Nokia 6600 blocks forever

    do you solve this problem, if so pls give me some advice.. thanks very much!

  10. #10
    Registered User
    Join Date
    Mar 2009
    Posts
    2

    Re: Socket read on Nokia 6600 blocks forever

    I have the same issue on Nokia E50.
    Please, post solution if it is available.

Posting Permissions

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