×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    2

    Post SocketConnection inputstream available() returns 0 bytes in S40 5th edition emulator

    Hi all,

    I have a java ME game MIDlet that runs 2 threads, a rendering loop and a thread that manages network I/O. It runs great on S60 emulator and has already been tested on ~40 S60 devices and works OK. However on S40 5th edition emulator, I never get any input from the network: inputStream.available() always returns 0 bytes available, even though on the Diagnostics window I see that I have received 15 bytes from the server. Part of networking thread code follows:

    Code:
    public void run() {
            SocketConnection sc = null;
            InputStream is = null;
            OutputStream os = null;
            try {
                sc = (SocketConnection) Connector.open("socket://" + serverName + ":" + sockNum);
                is = sc.openInputStream();
                os = sc.openOutputStream();
            } catch (IOException ex) {
                // handle
            } catch (SecurityException ex) {
                 // handle
            }
            if ((sc == null)  || (is == null) || (os == null)) {
                // exit thread in case any of the above is null
                return;
            }
            while (!done) {
                try {
                    if (is.available() > 0) {
                        // code to read from tcp socket and parse...
                    }
                    if (toSend.size() > 0) {
                        // send outgoing
                    }
            }
    }
    The problem with the code above is that on S40 5th ed. FP1 emulator, is.available() will always return 0 even though on the traffic monitor I can see that I have 15 bytes received through the TCP socket.

    Tried the following without any result:

    * Setting socket options to "magic" values, as suggested in another thread.
    * Instead of checking whether any bytes are available, try to read directly from the input stream: read methods always blocked without receiving any data.
    * Instead of socket.openInputStream() used socket.openDataInputStream() and tried reading with readByte(): same as above, operation blocked without receiving anything.

    Looks like I have hit a dead-end... Any suggestions / pointers for documentation to check out what is going wrong?

    Thanks in advance!

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: SocketConnection inputstream available() returns 0 bytes in S40 5th edition emula

    This Socket connection cannot work on S40 emulator, try on WTK it will work. I/O streams on socket connection are not realiable on emulators, it may also fail on real S40 device. Beter way will be to use HTTPConnection on S40 instaed of socket connection and route it thu HTTP Proxy if your server can support direct Httpcalls.

    thanks,
    ~Amitabh

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    2

    Re: SocketConnection inputstream available() returns 0 bytes in S40 5th edition emula

    Thank you for your responses.

    @im2amit: yes, we have been able to use this on Sun's WTK, Nokia S60, S-E JP7 and Motorola emulators - we only have this sort of problem with S40. We would love to have this solved on S40 as we need server-push properly implemented with a tcp socket.

    @traud, we have tested skipping the "is.available() > 0" check, instead reading directly from the InputStream using "int bytesRead = is.read(bytes, 0, bytes.length)" or "int nextByte = is.read();", however both calls return -1 meaning the end of stream has been reached according to javadoc which is quite absurd!

    any other ideas?

  5. #5
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: SocketConnection inputstream available() returns 0 bytes in S40 5th edition emula

    S40 emultators and early S40 devices do not support SocketConnection and streams on this type of connection is not reiable on these basic phones resulting in such issues.

    Only solution will be use HTTP Proxy with SMS wakeup or always on polling depening on http timeout and you can try http1.1 keep alive, but you cannot maintain socket connection and work using TCP CIR on these devices. InputStreams are not realiable here when opened on Socket.

    On this platform, you will be able to read the inputstream on socket, only when it is flushed and closed from the server side.

    thanks,
    ~Amitabh

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    2

    Re: SocketConnection inputstream available() returns 0 bytes in S40 5th edition emula

    I experience this too on nokia S40 5th Edition FP1 emulator and also the handset that based on this SDK ... but the funny part is, my chat program running very well on Nokia 3110 classic which is based on older SDK: S40 3rd Edition ... funny

Similar Threads

  1. S60 5th Edition emulator startup problem
    By gopitek in forum Symbian
    Replies: 2
    Last Post: 2010-09-08, 08:05
  2. S60 5th Edition SDK Emulator -- SLOW
    By earamsey in forum Symbian Tools & SDKs
    Replies: 4
    Last Post: 2010-01-18, 19:48
  3. Replies: 1
    Last Post: 2008-12-03, 16:56
  4. Personal
    By JSmith77 in forum PersonalJava
    Replies: 4
    Last Post: 2003-07-30, 12:52

Posting Permissions

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