RConnection and RSocket
Login to reply to this topic.
Thu, 2005-01-13 10:14
Joined: 2004-12-29
Forum posts: 8
Hello All

I have established a GPRS connection using Rconnection class, which is established successfully. Now I want to use the same connection for y sockets so that it doesn't ask for IAP as it has already done while establishing connection.
For this I have used following API of RSocket class

TInt Open(RSocketServ& aServer,TUint addrFamily,TUint sockType,TUint protocol, RConnection& aConnection);

But the problem is my application crashes at this function call and I cant check it on emulator as GPRS connection is not established over emulator.

Can anybody please guide what is causing mine application to crash as same application works well with other API of RSocket.

Regards,
Pankaj

Sat, 2005-01-15 22:27
Joined: 2005-01-15
Forum posts: 10
The RConnection seems to be buggy on the Series80 SDK.

Even the Symbian apps. on the emulator  crash sometimes when reusing an existing connection.

I have also found that the RConnection::enum_connections function seems not to return valid active connections.

Has anybody else found this?? Or perhaps a solution?

regards
John

John Read
NewNet Marketing
Munich, germany

Mon, 2005-01-17 05:51
Joined: 2004-12-29
Forum posts: 8
I dont think problem has to do something with Series80 SDK, in my view its generic problem irrespective of Series as I am trying on Series 60 Sdk 2.6 (Symbian 8.0a).

Regards
Pankaj
Tue, 2005-02-01 15:39
Joined: 2005-02-01
Forum posts: 36
Is your socket server connected?
Wed, 2005-02-02 13:37
Joined: 2004-12-29
Forum posts: 8
Yes, now I am able to connect using Socket server on emulator.
Fri, 2005-02-04 05:57
Anonymous (not verified)
Forum posts: 2037
hi
i have been trying to use the Nokia9200 communicator SDK for my project.I have 98 os and i can run only the basic examples which produces .exe but cant view the complete emulator.my 'abld build wins'  command is hanging while building the resource file.i dont have a mobile phone with me and i just want to view the emulator making a GPRS connection to the server.could u help me with the code u have for doing this.    Cry  Cry

thank u
Devi.
Wed, 2005-02-09 07:58
Joined: 2004-12-29
Forum posts: 8
Hello Devi

You cant check behavior of RConnection establishing GPRS connection as it shows no indication, anyways here is the code for establishing GPRS connection. I have tested this code on Series60 SDK 2.6

#include <eikgted.h>
#include <cdbcols.h>
#include <commdb.h>
#include <es_sock.h>
#include <eikenv.h>
#include <commdbconnpref.h>
#include <StringLoader.h>   // StringLoader
#include <TcpipMultiHomingEx.rsg>

#include "TcpipMultiHomingExAppui.h"
#include "TcpipMultiHomingExTimer.h"
#include "TcpipMultiHomingEx.pan"

const TInt KTextMaxLength = 30;
const TInt KTimeOut = 30000000; // 30 seconds time-out
const TInt KDefaultPortNumber = 777;

// default values to acces daytime server
_LIT(KDefaultServerName, "time-a.nist.gov");


CTcpipMultiHomingExEngine* CTcpipMultiHomingExEngine::NewL(MTcpipMultiHomingExEngineObserver& aObserver)
   {
   CTcpipMultiHomingExEngine* self = CTcpipMultiHomingExEngine::NewLC(aObserver);
   CleanupStack::Pop(self);
   return self;
   }


CTcpipMultiHomingExEngine* CTcpipMultiHomingExEngine::NewLC(MTcpipMultiHomingExEngineObserver& aObserver)
   {
   CTcpipMultiHomingExEngine* self = new (ELeave) CTcpipMultiHomingExEngine(aObserver);
   CleanupStack::PushL(self);
   self->ConstructL();
   return self;
   }


CTcpipMultiHomingExEngine::CTcpipMultiHomingExEngine(MTcpipMultiHomingExEngineObserver& aObserver)
: CActive(EPriorityStandard),
 iObserver(aObserver),
 iPort(KDefaultPortNumber),
 iServerName(KDefaultServerName)
   {
   }


CTcpipMultiHomingExEngine::~CTcpipMultiHomingExEngine()
   {
   iEngineStatus = EDestroyed;
   Cancel();

   delete iTimer;

   if (iSocketServ.Handle() != 0)
      {
      iSocketServ.Close();
      }
   }


void CTcpipMultiHomingExEngine::ConstructL()
   {
   ChangeStatus(ENotConnected);

   // Start a timer
   iTimer = CTcpipMultiHomingExTimer::NewL(EPriorityHigh, *this);
   CActiveScheduler::Add(this);

   // Open channel to Socket Server
   User::LeaveIfError(iSocketServ.Connect());
   }


void CTcpipMultiHomingExEngine::ConnectL()
   {
   // Initiate connection process
   if (iEngineStatus == ENotConnected)
       {

      //Open an RConnection on the Socket Server
      User::LeaveIfError(iRConn.Open(iSocketServ));

      // Start the Connection
      iRConn.Start(iStatus);
      ChangeStatus(ERConnStarting);
      iTimer->After(KTimeOut);
      SetActive();
       }
   }


void CTcpipMultiHomingExEngine::ConnectL(TUint32 aAddr)
   {
   // Initiate attempt to connect to a socket by IP address
   if (iEngineStatus == ENotConnected)
       {
       // Open a TCP socket
       User::LeaveIfError(iSocket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp, iRConn));

       // Set up address information
       iAddress.SetPort(iPort);
       iAddress.SetAddress(aAddr);

       // Initiate socket connection
       iSocket.Connect(iAddress, iStatus);
       ChangeStatus(EConnecting);

       // Start a timeout
       iTimer->After(KTimeOut);

       SetActive();
       }
   }


void CTcpipMultiHomingExEngine::Disconnect()
   {
   // cancel all outstanding operations
   Cancel();
   iSocket.Close();
   ChangeStatus(ENotConnected);
   }


// from CActive
void CTcpipMultiHomingExEngine::DoCancel()
   {
   iTimer->Cancel();

   TEngineState state = ENotConnected;
   // Cancel appropriate request to socket
   switch (iEngineStatus)
       {
      case EDestroyed:
         state = EDestroyed;
      case ENotConnected:
      case ERConnStarting:
       case EConnecting:
      case EConnected:
       case ELookingUp:
      case EReading:
         if (iRConn.SubSessionHandle() != 0)
            {
            iRConn.Close();
            }
           if (iResolver.SubSessionHandle() != 0)
            {
            iResolver.Cancel();
            iResolver.Close();
            }
            if (iSocket.SubSessionHandle() != 0)
            {
            iSocket.CancelAll();
             iSocket.Close();
            }
         break;
       default:
           User::Panic(KPanicTcpipMultiHomingExEngine, ETcpipMultiHomingExBadStatus);
           break;
       }

   ChangeStatus(state);
   }


void CTcpipMultiHomingExEngine::Read()
   {
   // Initiate read of data from socket
   if (iEngineStatus == EConnected)
       {
      // Initiate a new read from socket into iBuffer
      __ASSERT_ALWAYS(!IsActive(), User::Panic(KPanicTcpipMultiHomingExEngineRead, ETcpipMultiHomingExBadState));
      iSocket.RecvOneOrMore(iBuffer, 0, iStatus, iLength);
      ChangeStatus(EReading);
      SetActive();
       }
   }


// from CActive
void CTcpipMultiHomingExEngine::RunL()
   {
   // Active object request complete handler.
   // iEngineStatus flags what request was made, so its
   // completion can be handled appropriately
   iTimer->Cancel(); // Cancel TimeOut timer before completion

   switch(iEngineStatus)
       {

      case ERConnStarting:
         // need to look up name using dns
         // Initiate DNS
         User::LeaveIfError(iResolver.Open(iSocketServ, KAfInet, KProtocolInetUdp, iRConn));
         // DNS request for name resolution
         iResolver.GetByName(iServerName, iNameEntry, iStatus);

         ChangeStatus(ELookingUp);
         // Request time out
         iTimer->After(KTimeOut);
         SetActive();
         break;

       case ELookingUp:
          iResolver.Close();
          if (iStatus == KErrNone)
              {
             // DNS look up successful
             iNameRecord = iNameEntry();

               ChangeStatus(ENotConnected);
            TInetAddr lInetAddr;
            _LIT(KInetAddr,"10.203.140.33");
            lInetAddr.Input(KInetAddr);
             ConnectL(lInetAddr.Address());
              }
          else
              {
               // DNS lookup failed
            Cancel();
            ReportErrorL(EDNSLookupFailed, iStatus.Int());
              }
          break;

       case EConnecting:
          // IP connection request
          if (iStatus == KErrNone)
              // Connection completed successfully
              {
             ChangeStatus(EConnected);
            // Get the time
             Read();
              }
          else
              {
             Cancel();
            ReportErrorL(EConnectionFailed, iStatus.Int());
               }
          break;
      case EReading:
         {
         switch (iStatus.Int())
            {
            case KErrNone:
               {
               // Character has been read from socket
               TBuf<KReadBufferSize> unicodeBuf;
               unicodeBuf.Copy(iBuffer);
               iObserver.ResponseReceivedL(unicodeBuf);
               Disconnect();
               }
               break;
             case KErrDisconnected:
               {
               Cancel();
               ReportErrorL(EDisconnected, iStatus.Int());
               }
               break;
            default:
               {
               Cancel();
               ReportErrorL(EGeneralReadError,iStatus.Int());
               }
               break;
            }
         break;
         }

       default:
           User::Panic(KPanicTcpipMultiHomingExEngine, ETcpipMultiHomingExBadStatus);
           break;

       };
   }


void CTcpipMultiHomingExEngine::TimerExpiredL()
   {
   Cancel();
   ReportErrorL(ETimedOut,KErrTimedOut);
   }


void CTcpipMultiHomingExEngine::ReportErrorL(TErrorType aErrorType, TInt aErrorCode)
   {
   // No recovery or retries are attempted in this example so we just
   // disconnect and inform the user
   Disconnect();
   TBuf<KTextMaxLength> text;

   switch (aErrorType)
       {
       case EDisconnected:
         StringLoader::Load(text, R_DISCONNECTED_TEXT);
           iObserver.ErrorL(text, aErrorCode);
           break;
       case EGeneralReadError:
         StringLoader::Load(text, R_READ_ERROR_TEXT);
           iObserver.ErrorL(text, aErrorCode);
           break;
      case EConnectionFailed:
         StringLoader::Load(text, R_CONN_FAILED_TEXT);
         iObserver.ErrorL(text, aErrorCode);
         break;
      case EDNSLookupFailed:
         StringLoader::Load(text, R_DNS_ERROR_TEXT);
         iObserver.ErrorL(text, aErrorCode);
         break;
      case ETimedOut:
         StringLoader::Load(text, R_TIMED_OUT);
         iObserver.ErrorL(text, KErrTimedOut);
         break;
       default:
           User::Panic(KPanicTcpipMultiHomingExEngine, ETcpipMultiHomingExBadStatus);
           break;
       }
   }


void CTcpipMultiHomingExEngine::ChangeStatus(TEngineState aNewStatus)
   {
   TBuf<KTextMaxLength> text;

   // Update the status (and the status display)
   switch (aNewStatus)
       {
       case ENotConnected:
         StringLoader::Load(text, R_NOT_CONNECTED_TEXT);
           iObserver.SetStatus(text);
           break;
      case ERConnStarting:
         StringLoader::Load(text, R_RCONNECTING_TEXT);
           iObserver.SetStatus(text);
         break;
       case EConnecting:
         StringLoader::Load(text, R_CONNECTING_TEXT);
           iObserver.SetStatus(text);
           break;
       case EConnected:
           StringLoader::Load(text, R_CONNECTED_TEXT);
           iObserver.SetStatus(text);
           break;
       case ELookingUp:
         StringLoader::Load(text, R_LOOKINGUP_TEXT);
           iObserver.SetStatus(text);
           break;
      case EReading:
         StringLoader::Load(text, R_READING_TEXT);
         iObserver.SetStatus(text);
         break;
      case EDestroyed:
         break;
       default:
           User::Panic(KPanicTcpipMultiHomingExEngine, ETcpipMultiHomingExBadStatus);
           break;
       }

   iEngineStatus = aNewStatus;
   }
Fri, 2005-07-15 16:02
Joined: 2005-06-08
Forum posts: 53
Quote from: Pankaj
Hello All

I have established a GPRS connection using Rconnection class, which is established successfully. Now I want to use the same connection for y sockets so that it doesn't ask for IAP as it has already done while establishing connection.
For this I have used following API of RSocket class

TInt Open(RSocketServ& aServer,TUint addrFamily,TUint sockType,TUint protocol, RConnection& aConnection);

But the problem is my application crashes at this function call and I cant check it on emulator as GPRS connection is not established over emulator.

Can anybody please guide what is causing mine application to crash as same application works well with other API of RSocket.

Regards,
Pankaj

Thanks for your tip, Now I got it!

copyright 2003-2009 NewLC SARL