×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    7

    Explicitly close socket connection

    Hi

    my MIDlet communicates with a server using j2me socket connection. The connection is beeing opened using:

    Code:
    (SocketConnection) conn = Connector.open("socket://myhost.com:myPort")
    ..and after sending and receiving from the in- and outputstream resp. I close the connection using:

    Code:
    conn.close();
    BUT the phone does not actually 'close' the connection, i.e. my Nokias (6630, 6680) still show the 3G <=> symbol for beeing connected. This eventually changes when I shutdown my MIDlet.
    Do I have an error in my code or is this behaviour normal. And if so, how can I explicitly close the connection and stop the phone from using expensive network sources?

    Any help appreciated!
    Thanx, Phibo

  2. #2
    Nokia Developer Expert
    Join Date
    Jun 2005
    Posts
    923

    Re: Explicitly close socket connection

    Hi Phibo,

    This is normal behavior. Even after you explicitly close the connection and the I/O stream, the phone will still be connected for a while. This happens because opening a connection is very expensive and takes some time, so it still stays connected just in case your application needs another connection anytime soon.

    In Series 40, it will disconnect after some time with no activities.

    In Series 60, it will disconnect when you shutdown the midlet, but note that despite being connected, if it's not exchanging any data, you're not paying anything for this period.

    Daniel

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    7

    Re: Explicitly close socket connection

    I've also run into this "issue". I'd like to be able to explicity close the HTTP connection that my MIDlet is using. Even after calling all the appropriate close() methods on the streams and connection object, the actual connection is never truly closed, it just remains open but inactive. Surely there is a way of closing the connection completely, *without* shutting down my MIDlet?

  4. #4
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: Explicitly close socket connection

    like daniel said, it is not an "issue", it is a feature. you do not want the 3G connection to be shut down. (and btw, your http connection _is_ closed after the close() method)

  5. #5
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Explicitly close socket connection

    Quote Originally Posted by wguo View Post
    I've also run into this "issue". I'd like to be able to explicity close the HTTP connection that my MIDlet is using. Even after calling all the appropriate close() methods on the streams and connection object, the actual connection is never truly closed, it just remains open but inactive. Surely there is a way of closing the connection completely, *without* shutting down my MIDlet?
    Was better if you could share the device family.
    Are you testing this on the Emulator or on the real device?
    What harms it is doing if it not actually connected?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  6. #6
    Registered User
    Join Date
    Mar 2010
    Posts
    7

    Re: Explicitly close socket connection

    Hi,

    To be specific, I'm developing for S60 3rd devices. The purpose of my app is to monitor connection events made by a third party application (the monitoring portion is written in native Symbian C++). The third party app does synchronization of PIM data, and my app monitors it for how long the whole process takes.

    However, my app *also* has to connect to a server to send the sync duration result. What ends up happening is if my app (MIDlet) opens a HTTP connection, and the 3rd party app somehow uses the same connection to do its own tasks, then no connection events are logged for the 3rd party app. And the HTTP connection is kept "open" for the life of the MIDlet.

    Apparently the consequence is that I have to trigger the 3rd party app first, monitor its connection events, once 3rd party is finished, THEN launch my MIDlet to open its own HTTP connection and send the results. Otherwise the MIDlet launching a HTTP connection interferes with 3rd party app connection events.

    Sorry if this is confusing, I'm just explaining why this "keep-alive" of HTTP connection affects my project. I'll just have to re-design my app to work around this connection persistence.

  7. #7
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Explicitly close socket connection

    Quote Originally Posted by wguo View Post
    Hi,

    I'm developing for S60 3rd devices. The purpose of my app is to monitor connection events made by a third party application (the monitoring portion is written in native Symbian C++). The third party app does synchronization of PIM data, and my app monitors it for how long the whole process takes.
    Explain the quoted lines above...
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

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

    Re: Explicitly close socket connection

    However, my app *also* has to connect to a server to send the sync duration result. What ends up happening is if my app (MIDlet) opens a HTTP connection, and the 3rd party app somehow uses the same connection to do its own tasks, then no connection events are logged for the 3rd party app. And the HTTP connection is kept "open" for the life of the MIDlet.
    Just use your symbian app; to write this info to server and it will monitor or log its own server request and log event for it.

    thanks,
    ~Amitabh

Similar Threads

  1. Close HTTp Connection in N6230i
    By cars2004 in forum Mobile Java General
    Replies: 1
    Last Post: 2005-06-24, 10:46
  2. Close HTTp Connection in N6230i
    By cars2004 in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2005-06-24, 09:29
  3. socket connection problem
    By bhatti81 in forum Mobile Java General
    Replies: 2
    Last Post: 2003-10-08, 14:43
  4. opening a socket connection
    By bhatti81 in forum Mobile Java Networking & Messaging & Security
    Replies: 4
    Last Post: 2003-07-16, 10:08
  5. PC Sync with 6310i and Socket BT Connection Kit
    By sami_laiho in forum Bluetooth Technology
    Replies: 0
    Last Post: 2002-09-17, 05:25

Posting Permissions

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