×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Russia, Bryansk
    Posts
    90

    http. Phone hangs.

    Hi!

    I have the problem with the http connection. If I let the phone ask the user each time the application connects to the internet, the app hanges after the user refuses the connection in the second or other not-first time.

    The same code works fine on Sony Ericsson K800i phone.

    Was tested on Nokia 6230i, 6260.

    Code:
        void connect()
        {
            OutputStream out = null;
            InputStream in = null;
            byte [] buffer = null;
    
            int outLen = outBuff.pos;
            
            try
            {
                httpConnection = (HttpConnection)Connector.open(serverURL);
    
                httpConnection.setRequestMethod(httpConnection.POST);
                httpConnection.setRequestProperty("Content-Length", ""+outLen);
                httpConnection.setRequestProperty("Content-Type", "image/jpeg");
                
                if( mSession != null )
                {
                    httpConnection.setRequestProperty("Cookie", mSession);
                }
                
                out = httpConnection.openOutputStream();
    
                out.write( outBuff.data, 0, outLen);
                
                out.close();
                out = null;
    
                in = httpConnection.openInputStream();
                
                String cookie = httpConnection.getHeaderField("Set-cookie");
                if (cookie != null) {
                    int semicolon = cookie.indexOf(';');
                    mSession = cookie.substring(0, semicolon);
                }
    
                
                byte inByte;
                int inLen = 0;
                
                buffer = inBuff.data;
                
                while( (inByte = (byte)in.read())!=-1 )
                {
                    buffer[ inLen ] = inByte;
                    inLen++;
                }
    
                in.close();
                in = null;
                httpConnection.close();
                httpConnection = null;
                
                Game.instance.networkResponseFlag = true;
            }
            catch (Exception ioe)
            {
                if (cancelConnect == false)
                {
                    try
                    {
                        if (out != null) out.close();
                        if (in != null) in.close();
                        if (httpConnection != null) {httpConnection.close();httpConnection=null;}
                    }
                    catch (Exception e) {};
                    connectionFailed(); // show the user that the connaction failed
                }
            }
            finally
            {
                cancelConnect = false;
            }
        }

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Russia, Bryansk
    Posts
    90

    Re: http. Phone hangs.

    Any ideas? Please...

Similar Threads

  1. Connecting from PC to phone via RFCOMM, OBEX
    By buzz111 in forum Symbian
    Replies: 4
    Last Post: 2007-03-01, 05:48
  2. HTTP Client - Synchronous HTTP POST Calls?
    By symbian_ravi in forum Symbian Networking & Messaging (Closed)
    Replies: 5
    Last Post: 2006-04-16, 11:51
  3. http connection via a proxy programmatically
    By tiansun in forum Mobile Java General
    Replies: 0
    Last Post: 2005-04-19, 02:47
  4. Uniquely recognize phone where http request is coming from
    By j_jokisalo in forum Mobile Java General
    Replies: 3
    Last Post: 2003-03-25, 12:51

Posting Permissions

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