×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Mar 2006
    Location
    Pune, India
    Posts
    75

    How to Disconnect RConnection

    Hi,

    I am using a RConnection to open a WLan connection. Below is the code


    Header file
    Code:
    class CConnectionMaker : public CActive
    	{
    public:
    	static CConnectionMaker* NewL();
    	static CConnectionMaker* NewLC();
    	~CConnectionMaker();
    
    public:
    	void ConnectL(TUint32 aIapId);
    	void Disconnect();
    
    protected:
    	void DoCancel();
    	void RunL();
    	TInt RunError(TInt aError);
    	static TInt TimeoutCallback(TAny* aAny);
    
    private:
    	CConnectionMaker();
    	void ConstructL();
    
    private:
    	RSocketServ iSocketServer;
    	RConnection iConnection;
    	CPeriodic* iPeriodic;
    
    public:
    	};
    Source file
    Code:
    CConnectionMaker * CConnectionMaker::NewL()
    	{
    	CConnectionMaker* self = NewLC ();
    	CleanupStack::Pop (self);
    	return self;
    	}
    
    CConnectionMaker* CConnectionMaker::NewLC()
    	{
    	CConnectionMaker* self = new (ELeave) CConnectionMaker();
    	CleanupStack::PushL (self);
    	self->ConstructL ();
    	return self;
    	}
    
    CConnectionMaker::~CConnectionMaker()
    	{
    	Deque();
    	delete iPeriodic;
    	iConnection.Close ();
    	iSocketServer.Close ();
    	}
    
    CConnectionMaker::CConnectionMaker() :
    	CActive(CActive::EPriorityStandard)
    	{
    	}
    
    void CConnectionMaker::ConstructL()
    	{
    	User :: LeaveIfError (iSocketServer.Connect (KESockDefaultMessageSlots));
    
    	/** create the timeout timer */
    	iPeriodic = CPeriodic::NewL (EPriorityStandard);
    
    	/** Add to active scheduler */
    	CActiveScheduler::Add (this);
    	}
    
    void CConnectionMaker::DoCancel()
    	{
    	iPeriodic->Cancel ();
    	iConnection.Close();
    	}
    
    void CConnectionMaker::RunL()
    	{
    	User::LeaveIfError(iStatus.Int());
    
    	iPeriodic->Cancel ();
    	// some notification code
    	........
    	}
    
    TInt CConnectionMaker::RunError(TInt aError)
    	{
    	iPeriodic->Cancel ();
    	// some notification code
    	........
    	return KErrNone;	
    	}
    
    void CConnectionMaker::ConnectL(TUint32 aIapId)
    	{
    	Cancel ();
    	iConnection.Close ();
    
    	User :: LeaveIfError (iConnection.Open (iSocketServer));
    
    	TCommDbConnPref prefs;
    	prefs.SetDialogPreference (ECommDbDialogPrefDoNotPrompt);
    	prefs.SetDirection (ECommDbConnectionDirectionOutgoing);
    	prefs.SetIapId (aIapId);
    
    	iConnection.Start (prefs, iStatus);
    	SetActive ();
    	iPeriodic->Start (250000000, 250000000, TCallBack (CConnectionMaker::TimeoutCallback, this));
    	}
    
    void CConnectionMaker::Disconnect()
    	{
    	iConnection.Close();
    	}
    
    TInt CConnectionMaker::TimeoutCallback(TAny* aAny)
    	{
    	CConnectionMaker* parent = static_cast<CConnectionMaker*>(aAny);
    	parent->iConnection.Stop();
    	return KErrNone;
    	}
    Now when I am trying to connect to a access point for the first time I am able to connect to it.
    When I forcefully disconnect it with "Conn. Mgr." it get disconnected (the icon vanish). When I try to connect it second time it cannot start connection and my Timer expires. This connection is in midway as my RunL is not called for very long time. So I call iConnection->Stop(); My RunL is called after but this Connection is not closed (even if i closed my application). I still see icon and connecting status in "Conn. mgr.".

    I have to explectly delete it with "Conn. mgr."

    Can some one help me in figuring out the problem

    Also how "conn. mgr." achive this functionality of disconnection. I could even use that to release the connection.

    Regards
    Ashfaq Ghori
    Ashfaq Ghori
    Symbian Developer
    Mumbia - India

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: How to Disconnect RConnection

    Note that RConnection::Stop needs NetworkControl (NetworkServices is not enough) capability. Have you tried Close-ing and re-Open-ing the RConnection before a new Start?

  3. #3
    Super Contributor
    Join Date
    Jun 2005
    Location
    Berlin
    Posts
    721

    Re: How to Disconnect RConnection

    with RConnection::Stop(), I can only disconnect this connection created by this RConnection.

    If there are any other applications running with the connection(WLan), then the RConnection::Stop() doesn't work any more.


    Is that mean, I nead the NetworkControl to do this?



    Thanks

    Pai

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: How to Disconnect RConnection

    Quote Originally Posted by paipeng View Post
    with RConnection::Stop(), I can only disconnect this connection created by this RConnection.
    No. Feel free to check it in the SDK Help.
    If there are any other applications running with the connection(WLan), then the RConnection::Stop() doesn't work any more.

    Is that mean, I nead the NetworkControl to do this?
    RConnection::Stop simply returns KErrPermissionDenied if you use it without having NetworkControl. However if you invoke RConnection::Close - indicating that your application will not like to use the connection any more -, and no other applications use the same (for example WLAN) interface, the connection will usually shut down.
    Generally you do not need RConnection::Stop, since the connection will behave as specified by the user (in the Settings application), thus usually close when unused.

  5. #5
    Super Contributor
    Join Date
    Jun 2005
    Location
    Berlin
    Posts
    721

    Re: How to Disconnect RConnection

    Yes wizard_hu, I get 'KErrPermissionDenied -46' by RConnection::Stop.
    (Can I do this disconnection when I have the 'NetworkControl' capability, when other applications use this interface, like WLan?)

    I use this 'Stop' function, only want to switch the wlan-connections between access points automatically/programmatically.

    is this kind of switching(like roaming/handover) possible with S60 3rd SDK?


    Thanks again.

    Pai

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: How to Disconnect RConnection

    Quote Originally Posted by paipeng View Post
    (Can I do this disconnection when I have the 'NetworkControl' capability, when other applications use this interface, like WLan?)
    Quote Originally Posted by wizard_hu_
    Feel free to check it in the SDK Help.

    And here come at least 10 characters, of course.

  7. #7
    Super Contributor
    Join Date
    Jun 2005
    Location
    Berlin
    Posts
    721

    Re: How to Disconnect RConnection

    Quote Originally Posted by wizard_hu_ View Post
    And here come at least 10 characters, of course.
    Thanks wizard hu for your attention and answer.

    Yes, there are many questions on the forum which can be answered by self checking the docs.

    Only if the docs is written well.

    After checking the SDK of 9.1, 9.2 and 9.3(beta). and found another topic about this poblem, I must say, i can't find the answer in docs of SDKs.

    http://discussion.forum.nokia.com/fo...ad.php?t=85091

    I'd better check/search in the forum first, before I ask again...


    finally, I found it in sdk, with help of

    https://developer.symbian.com/forum/...7105&tstart=45
    Last edited by paipeng; 2008-03-12 at 14:38.

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: How to Disconnect RConnection

    I do not have every possible SDK-s installed, but in 3rd MR:
    Quote Originally Posted by SDK Help, RConnection::Stop
    Stop()
    IMPORT_C TInt Stop();
    Description
    Stops the entire connection by disconnecting the underlying network interface immediately, regardless of whether other clients are using it or not.

    Applications using the connection will be sent the socket error code KErrCancel. The application generally responds with clean up operations and pop-up boxes alerting the user to the termination of the application.

    Return value
    TInt KErrNone if successful, otherwise another of the system wide error codes.

    Note that the first relevant hit for RConnection from Google also says
    Disconnect the underlying interface immediately (regardless of whether other clients are using it or not).

  9. #9
    Super Contributor
    Join Date
    Jun 2005
    Location
    Berlin
    Posts
    721

    Re: How to Disconnect RConnection

    Of course right, I read it too, only one thing, when it works (without -46 or anything else).

    Now the problem is, it doesn't work. And I have found the needed capabilitiy name not directly on that SDK page, but from you and the links.

Similar Threads

  1. simple RConnection question
    By rtrnokia in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2007-11-21, 07:59
  2. Get disconnect Button event
    By anoopd in forum Symbian
    Replies: 10
    Last Post: 2007-06-14, 14:11
  3. Possible to monitor active data connections and disconnect after timeout?
    By ttempelmann in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2007-03-13, 20:46
  4. Replies: 1
    Last Post: 2006-03-07, 15:07
  5. how to disconnect on 7650
    By gerodol in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2003-05-30, 14:33

Posting Permissions

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