×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    20

    socket connection breaks after some time

    Hello all,

    I had developed a mobile messenger application which listen on a socket connection to communicate to the server.If i leave the application idle ,i mean do not do any operation on the application for say 15-20 minutes then the listener(which is always running to see of the incoming data) throws IOException.
    Socket connection is breaking. Am getting this error on sony ericsson w810I and Nokia n73,n70.
    Application is running fine on emulator for whatever time you want it to be idle(i mean i had not checked for days but for hours it runs fine).

    This the part of creating the socket connection
    SocketConnection sc =(SocketConnection)Connector.open("socket://URLort");
    sc.setSocketOption(SocketConnection.KEEPALIVE, 1);
    if(os == null) {
    os = sc.openOutputStream();
    }
    if(is == null) {
    is = sc.openInputStream();
    }

    Also catching the exceptions while creating socket.

    And this is listener

    public void incomingData() {
    Thread threadSocket = new Thread() {

    public void run() {
    StringBuffer sb = null;
    try {
    while (true) {

    if (sb == null) {
    sb = new StringBuffer();
    }
    int c = 0;

    while ((c = is.read()) != -1 && sb != null) {

    sb.append((char) c);

    Now i got all the data in SB stringbufer but the problem here application if left idle for 15-20 minute gets disconnected from the server.

    Can anyone please help in this regard.

    Thanks in advance.

    Best,
    Pradeep joon

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    11

    Re: socket connection breaks after some time

    Hi,

    I have the same problem. I have connected to the socket successfully. But when I want to send/receive data it fails. Is there any work around of this problem ?

    My code is here ..

    conn = (SocketConnection) Connector.open(guessURL(), Connector.READ_WRITE, true);

    conn.setSocketOption(SocketConnection.DELAY, 2);
    conn.setSocketOption(SocketConnection.LINGER, 0);
    conn.setSocketOption(SocketConnection.KEEPALIVE, 1);

    conn.setSocketOption(SocketConnection.SNDBUF, 1000);
    conn.setSocketOption(SocketConnection.RCVBUF, 1000);

    It just reads EOF everytime

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    11

    Re: socket connection breaks after some time

    Hi,

    Let me elaborate the issue ..

    I am trying with http://miniim.svn.sourceforge.net/vi...va?view=markup
    code to connect to xmpp server. Unfortunately it does not work on N72.

    I connect to jabber.org at port 5222 and send authentication data. The authentication mechanism is PLAIN and it sends base64 encoded data. The total thing works fine in wtk but not in N72. Note that it is the same authentication data sent to the server ..

    It seems that the server can understand the requests except my authentication request part(not sure if base64 is causing any encoding problem ).

    I am using kxml library to read and write xml data. This library auto-detect encoding while reading. And I am using UTF-8 encoding while writing data.

    Let me show you the log that it generates. The DumperOutputStream and DumperInputStream are like buffered streams with logging facility. I use these to wrap my io stream while debugging (I tried without this thing with same result) . In the log I changed my authentication data part to 'myauthdata' . And I also stripped the unnecessary log entries ..

    At first here is the successful log from wtk,

    Code:
    16	DEBUG	net.ayaslive.miniim.utils.io.DumperOutputStream	-382157135	139128459	>> 154 :<?xml version='1.0' encoding='UTF-8' ?><stream:stream xmlns="jabber:client" to="jabber.org" version="1.0" xmlns:stream="http://etherx.jabber.org/streams">		
    18	DEBUG	net.ayaslive.miniim.utils.io.DumperInputStream	357867388	139128459	<< 0 :<?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='2067063603' from='jabber.org' version='1.0' xml:lang='en'>		
    24	DEBUG	net.ayaslive.miniim.utils.io.DumperInputStream	357867388	139128459	<< 0 :<stream:features><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/><compression xmlns='http://jabber.org/features/compress'><method>zlib</method></compression><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism></mechanisms><register xmlns='http://jabber.org/features/iq-register'/></stream:features>		
    40	DEBUG	net.ayaslive.miniim.utils.io.DumperOutputStream	-382157135	139128459	>> 108 :<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">myauthdata</auth>		
    41	DEBUG	net.ayaslive.miniim.plugins.xmpp.XMPPInputStream	18786966	139128459	readSuccess()		
    42	DEBUG	net.ayaslive.miniim.utils.io.DumperInputStream	357867388	139128459	<< 0 :<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>		
    43	DEBUG	net.ayaslive.miniim.plugins.xmpp.XMPPOutputStream	207385393	139128459	reset()		
    44	DEBUG	net.ayaslive.miniim.utils.io.DumperOutputStream	-382157135	139128459	>> 154 :<?xml version='1.0' encoding='UTF-8' ?><stream:stream xmlns="jabber:client" to="jabber.org" version="1.0" xmlns:stream="http://etherx.jabber.org/streams">		
    45	DEBUG	net.ayaslive.miniim.plugins.xmpp.XMPPInputStream	18786966	139128459	reset()		
    46	DEBUG	net.ayaslive.miniim.utils.io.DumperInputStream	357867388	139128459	<< 0 :<?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='1640670864' from='jabber.org' version='1.0' xml:lang='en'>
    And here is the failure log from N72,

    Code:
    14	DEBUG	net.ayaslive.miniim.utils.io.DumperOutputStream	256757453	54423245	>> 154 :<?xml version='1.0' encoding='UTF-8' ?><stream:stream xmlns="jabber:client" to="jabber.org" version="1.0" xmlns:stream="http://etherx.jabber.org/streams">		
    17	DEBUG	net.ayaslive.miniim.utils.io.DumperInputStream	-345649459	54423245	<< 0 :<?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='3791307584' from='jabber.org' version='1.0' xml:lang='en'><stream:features><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/><compression xmlns='http://jabber.org/features/compress'><method>zlib</method></compression><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism></mechanisms><register xmlns='http://jabber.org/features/iq-register'/></stream:features>		
    38	DEBUG	net.ayaslive.miniim.utils.io.DumperOutputStream	256757453	54423245	>> 108 :<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">myauthdata</auth>		
    39	DEBUG	net.ayaslive.miniim.plugins.xmpp.XMPPInputStream	-243937587	54423245	readSuccess()		
    40	ERROR	net.ayaslive.miniim.plugins.xmpp.XMPPInputStream	-243937587	54423245	readSuccess()null		
    41	ERROR	net.ayaslive.miniim.common.IMMonitor	54423245	54423245	dispatch()	java.io.IOException	unexpected type (position:END_DOCUMENT null@1:531 in java.io.InputStreamReader@eb25cecd) ,tostring():java.io.IOException: unexpected type (position:END_DOCUMENT null@1:531 in java.io.InputStreamReader@eb25cecd)
    The problem is after sending auth data it closes connection and throws exception ..

    Please let me share your idea about this ..

    -- Thanks
    Kamanashis Roy

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    11

    Re: socket connection breaks after some time

    Hi, My problem is solved .. It was native UTF-8 implementation problem. Please refer to http://discussion.forum.nokia.com/fo...ad.php?t=76814 thread .

Similar Threads

  1. Tricky question inside - N95 (S60) socket connection: crazy latency times
    By Nodjo in forum Mobile Java Networking & Messaging & Security
    Replies: 4
    Last Post: 2007-12-29, 07:54
  2. Socket connection is doesn't work in nokia e70
    By omenz in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2007-06-18, 13:37
  3. Opening socket connection fails
    By Hardcoreprogrammer in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2005-01-17, 08:37
  4. Persistent connection using socket
    By yungsiu in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2004-11-12, 05:47
  5. Closing a Socket Connection
    By maniac_2k in forum Symbian Networking & Messaging (Closed)
    Replies: 4
    Last Post: 2004-08-03, 14:36

Posting Permissions

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