×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    5

    Few queston about sockets

    Hi there,

    I've made a program which sends every 6sec 100 character long data to server. Also if send fails, I put the data in db and at later try to send again.

    Now I've faced a small issue. In first try, I get KErrNoMemory when program was running a while.
    But when I changed on thing error was gone(see the bold code), or so it looks like..

    Also I have to write one data at time to server, so if someone knows much better solution please advise
    Sending current data:
    Code:
    void CSocketSender::SendL(TInetAddr aAddrs,const TDesC8& aRequest)
    	{
    		iRequest = aRequest;
    		TInt ret = iSocket.Open(iSocketServer,
    					KAfInet,
    					KSockStream,
    					KProtocolInetTcp);
    		if(ret == KErrNone)
    			{
    			iState = EConnecting;
    			iSocket.Connect(aAddrs,iStatus);
    			SetActive();
    			}
    		else
    			{
    			iNotifier.SendCompletedL(ret,iRequest);
    			}
    	}
    Sending old data,only the callback function is different:
    Code:
    void CSocketSender::SendBuffer(TInetAddr aAddrs,const TDesC8& aRequest)
    	{
    
    	iRequest = aRequest;
    	TInt ret = iSocket.Open(iSocketServer,
    				KAfInet,
    				KSockStream,
    			        KProtocolInetTcp);
    	if(ret == KErrNone)
    		{
    		iState = EConnectingbuffer;
    		iSocket.Connect(aAddrs,iStatus);
    		SetActive();
    		}
    	else
    		{
    			iNotifier.BufferSendCompletedL(ret);
    		}
    	}
    And RunL:
    Code:
    void CSocketSender::RunL()
    	{
    		
    	switch(iState)
    		{
    		case EConnecting:
    			{
    
    				iState = ESendingCurrent;
    				
    				iSocket.Write(iRequest,iStatus);
    				SetActive();
    				break;
    			}
    		case EConnectingbuffer:
    			{
    				iState = ESendingBuffer;
    				iSocket.Write(iRequest,iStatus);
    				SetActive();
    				break;
    			}
    		case ESendingCurrent:
    			{
    				Cancel();
    					
    				iState = ESendingBuffer;
    				iNotifier.SendCompletedL(iStatus.Int(),iRequest);
    				
    				break;
    			}
    		case ESendingBuffer: 
    			{
    				//before
                                        //Cancel()
                                    //After
                                 iSocket.CancelAll();
    				iSocket.Close();
    				iNotifier.BufferSendCompletedL(iStatus.Int());
    				
    				
    			break;
    			}
    		default:
    			break;
    		
    		}
    	
    	}
    And DoCancel()
    Code:
    void CSocketSender::DoCancel()
    	{
    		iSocket.CancelAll();
    		iSocket.Close();
    		
    		
    	}
    Edit: It didn't remove error
    Last edited by henrihar; 2009-02-23 at 16:52.

  2. #2
    Registered User
    Join Date
    Aug 2007
    Posts
    41

    Re: Few queston about sockets

    Hi!

    It didn't remove error

    It's obvious, because Cancel() method calls your DoCancel() implementation (which is quite the same with those two new added lines).

    Also I have to write one data at time to server, so if someone knows much better solution please advise

    I think, you could try to open several sockets concurrently.

    Regarding KErrNoMemory: what do you mean exactly? Does Open() method return KErrNoMemory value?

    Quote Originally Posted by henrihar View Post
    Hi there,

    I've made a program which sends every 6sec 100 character long data to server. Also if send fails, I put the data in db and at later try to send again.

    Now I've faced a small issue. In first try, I get KErrNoMemory when program was running a while.
    But when I changed on thing error was gone(see the bold code), or so it looks like..

    Also I have to write one data at time to server, so if someone knows much better solution please advise
    Sending current data:
    Code:
    void CSocketSender::SendL(TInetAddr aAddrs,const TDesC8& aRequest)
    	{
    		iRequest = aRequest;
    		TInt ret = iSocket.Open(iSocketServer,
    					KAfInet,
    					KSockStream,
    					KProtocolInetTcp);
    		if(ret == KErrNone)
    			{
    			iState = EConnecting;
    			iSocket.Connect(aAddrs,iStatus);
    			SetActive();
    			}
    		else
    			{
    			iNotifier.SendCompletedL(ret,iRequest);
    			}
    	}
    Sending old data,only the callback function is different:
    Code:
    void CSocketSender::SendBuffer(TInetAddr aAddrs,const TDesC8& aRequest)
    	{
    
    	iRequest = aRequest;
    	TInt ret = iSocket.Open(iSocketServer,
    				KAfInet,
    				KSockStream,
    			        KProtocolInetTcp);
    	if(ret == KErrNone)
    		{
    		iState = EConnectingbuffer;
    		iSocket.Connect(aAddrs,iStatus);
    		SetActive();
    		}
    	else
    		{
    			iNotifier.BufferSendCompletedL(ret);
    		}
    	}
    And RunL:
    Code:
    void CSocketSender::RunL()
    	{
    		
    	switch(iState)
    		{
    		case EConnecting:
    			{
    
    				iState = ESendingCurrent;
    				
    				iSocket.Write(iRequest,iStatus);
    				SetActive();
    				break;
    			}
    		case EConnectingbuffer:
    			{
    				iState = ESendingBuffer;
    				iSocket.Write(iRequest,iStatus);
    				SetActive();
    				break;
    			}
    		case ESendingCurrent:
    			{
    				Cancel();
    					
    				iState = ESendingBuffer;
    				iNotifier.SendCompletedL(iStatus.Int(),iRequest);
    				
    				break;
    			}
    		case ESendingBuffer: 
    			{
    				//before
                                        //Cancel()
                                    //After
                                 iSocket.CancelAll();
    				iSocket.Close();
    				iNotifier.BufferSendCompletedL(iStatus.Int());
    				
    				
    			break;
    			}
    		default:
    			break;
    		
    		}
    	
    	}
    And DoCancel()
    Code:
    void CSocketSender::DoCancel()
    	{
    		iSocket.CancelAll();
    		iSocket.Close();
    		
    		
    	}
    Edit: It didn't remove error
    Last edited by Damavik; 2009-02-25 at 13:52.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    41

    Re: Few queston about sockets

    What's more you could try using of debug macros and HookLogger tool just to ensure that memory is not leaked in your application.

Similar Threads

  1. help~~~about the CMdaAudioInputStream
    By Dragon_L in forum Symbian Media (Closed)
    Replies: 14
    Last Post: 2008-11-05, 06:11
  2. Using sockets in the fullduplex example
    By niranjancsc in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2007-03-22, 12:52
  3. YUCCA Help : BT Sockets : Wierd Problem??
    By mayur_24 in forum Symbian
    Replies: 5
    Last Post: 2004-09-20, 12:18
  4. Questions about sockets, I need help.
    By _fox in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2004-06-10, 10:29
  5. Where to find application that uses sockets?
    By doctordwarf in forum Mobile Java General
    Replies: 1
    Last Post: 2004-03-10, 15:45

Posting Permissions

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