×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    12

    UDP connection to server working on emulator but not on device !

    Hi

    I am sending a data from the mobile phone to a server using UDP. The application works fine when im using the emulator. The server is on a public IP in another machine. And the application is on my emulator. This setup works fine. Now problem comes when I load the application on to a real mobile phone. Here the application sends the message. I know this because I can see the GPRS symbol. But the server does not receive the message.
    Please help. The device is Nokia 6680. I am sending a simple "a" character to the server. I am sending it only once. I have tried sending it more than once also but it doesnt resolve the problem. Here is the code:

    Code:
    /*
     CEchoEngine: main engine class for connection and shutdown
    */
     CTcpEngine::CTcpEngine() : iStop(ETrue), CActive(EPriorityStandard)
    	{
    	}
    
     CTcpEngine* CTcpEngine::NewL()
    	{
    	CTcpEngine* self = NewLC();
    	CleanupStack::Pop();
    	return self;
    	}
    
     CTcpEngine* CTcpEngine::NewLC()
    	{
    	CTcpEngine* self = new(ELeave) CTcpEngine;
    	CleanupStack::PushL(self);
    	self->ConstructL();
    	return self;
    	}
    /*
     Constructs object, and opens a socket 
    */
     void CTcpEngine::ConstructL()
    	{
    	iEngineStatus = EComplete;
    	CActiveScheduler::Add(this);
    	// Open channel to Socket Server
    	User::LeaveIfError(iSocketServ.Connect());
    	// Open a TCP socket
    	User::LeaveIfError(iEchoSocket.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp));
    	TSockAddr addr;
    	addr.SetPort(1111);
    	TInt errcode = iEchoSocket.Bind(addr);
    	ConnectL(INET_ADDR(xxx,xx,xxx,xxx));
    	}
    
    void CTcpEngine::DoCancel()
    // Cancel asychronous requests
    	{
    
    	// Cancel appropriate request to socket
    	switch (iEngineStatus)
    		{
    	case EConnecting:
    		iEchoSocket.CancelConnect();
    		break;
    	default:;
    		}
    	}
    /*
     Connect to an Echo Socket by IP address	
    */
     void CTcpEngine::ConnectL(TUint32 aAddr)
    	{
    	// port number for test purposes - may need to be changed
    	iAddress.SetPort(4044);
    	iAddress.SetAddress(aAddr);
    	iEchoSocket.Connect(iAddress, iStatus);
    	iEngineStatus = EConnecting;
    	
    	SetActive();
    	}
    
    /*
    Exported function wrapping call to CEchoWrite: writes character to socket
    */
     void CTcpEngine::Write(TChar aChar)
    	{
       	/* 
    	In this simple implementation, if iEchoWrite is already active, ignore call.
    	Full implementation would buffer data 
    	*/
    	if (iEngineStatus == EConnected)
    		IssueWrite(aChar);
    	}
    /*
    Exported function wrapping call to CEchoRead: reads character from socket
    */	
     void CTcpEngine::Read()
    	{
    	if (iEngineStatus == EConnected) 
    		IssueRead();
    	}
    
    /*
     Active object request complete handler.
     iEngineStatus flags what request was made, so its
     completion can be handled appropriately
    */
    void CTcpEngine::RunL()
    	{
    	// Cancel TimeOut timer before completion
    	_LIT(KConnecting,"\n<CTcpEngine> Connecting\n");
    	_LIT(KConnectionFailed,"\n<CTcpEngine> Connection failed");
    	_LIT(KDNSFailed,"\n<CTcpEngine> DNS lookup failed");
    	_LIT(KTimedOut,"\n<CTcpEngine> Timed out\n");
    	_LIT(KDomainName,"\nDomain name = ");
    	_LIT(KIPAddress,"\nIP address = ");
    
    	TBuf<15> ipAddr;
    
    	switch(iEngineStatus)
    		{
    	case EConnecting:
    		// IP connection request
    		if (iStatus == KErrNone)
    		// Connection completed sucessfully
    		{
    		  		  
    			//iEngineStatus = EConnected;
    			iBuffer.SetLength(0);
    			iBuffer.Append('a');
    			iEchoSocket.SendTo(iBuffer,iAddress,NULL,iStatus);
    						
    			SetActive();
    		  	
    			
    		}
    		else
    			{
    			iEngineStatus = EConnectFailed;
    			}
    		
    		break;
    	 case EConnected:
    	     	      
    		      
    	
    	    break;
    	default:;
    		};
    	}
    
    CTcpEngine::~CTcpEngine()
    	{
    	iEchoSocket.Close();
    	iSocketServ.Close();
    	}
    
    /*
     Shutdown connection request
    */
     void CTcpEngine::Stop()
    	{
    	_LIT(KETerminate,"\n<CTcpEngine> Terminating\n");
    
    	switch (iEngineStatus)
    		{
    	case EConnected:
    		// Stop live connection
    	case EConnecting:
    		// if request to CTcpEngine, then stop it
    		Cancel();
    		break;
    	default:;
    		}
    	}
    
    /*
     Read data from a stream socket
    */
    void CTcpEngine::IssueRead()
    {
    	
    	//iEchoSocket.Recv(readBuf, 0, iStatus);
    	iEchoSocket.RecvFrom(readBuf, anAddr, 0, iStatus);
    	SetActive();
    }
    	
    /*
    Write data to a stream socket
    */
    void CTcpEngine::IssueWrite(const TChar &aChar)
    	{
    	// Set up buffer
    	iBuffer.SetLength(0);
    	iBuffer.Append(aChar);
    	iEchoSocket.Write(iBuffer, iStatus);
    	SetActive();
    	};

    Thanks in advance!
    Last edited by symbian2006; 2006-11-24 at 05:38.

  2. #2
    Regular Contributor
    Join Date
    May 2006
    Location
    Hyderabad,India
    Posts
    89

    Re: UDP connection to server working on emulator but not on device !

    if you want to send some thing out using udp.

    dont use """bind""".

    use setlocalport(1111) for setting port from which you want to send.

    after that use sendto

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


    Regards,
    Sheshu Kumar Inguva.

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

    Re: UDP connection to server working on emulator but not on device !

    Hi i have the same problem of gettin the udp datagram packets recvd/send tothe mobile device. with emulator it works fine.

    any clues and idea how to ?

    @mbersone
    4U@PedagogLtd

  4. #4
    Registered User
    Join Date
    Dec 2006
    Posts
    9

    Re: UDP connection to server working on emulator but not on device !

    Hello Ambersone,

    I wonder if you had the same problem I had.
    My app also worked ok on emulator, but on E61 (phone I was testing on) it was no good.

    It turned out that I had not allowed the needed "capabilities" for networking.
    Had I paid more attention to the debug output for the emulator I would have seen a message about some type of "capability" missing.

    As I am using Carbide as my IDE, I just had to add NetworkServices to the Capability line for the project property. I first did this to the mmp file, but I found out later this was the wrong place to do it.

    Please note that you will also need to have a correct certificate or, as I did, I turned off in the phone the need for this. This way the user gets a prompt at install time to allow or disallow the install. You will also see at this point what capabilities will be allowed.

    I hope that this helps

    Steve

  5. #5
    Regular Contributor
    Join Date
    Sep 2006
    Location
    Australia, NSW
    Posts
    200

    Re: UDP connection to server working on emulator but not on device !

    Quote Originally Posted by inguvaseshu
    if you want to send some thing out using udp.

    dont use """bind""".

    use setlocalport(1111) for setting port from which you want to send.

    after that use sendto

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


    Regards,
    Sheshu Kumar Inguva.
    Acutally using Bind is perfectly fine.

  6. #6
    Regular Contributor
    Join Date
    May 2006
    Location
    Hyderabad,India
    Posts
    89

    Re: UDP connection to server working on emulator but not on device !

    See i have some problem with bind to 0000 for listening to a udp port. instead we can use setLocalPort for listening port.

    For sending something out we dont need to bind.

    Here may be they have capability problem.

    Thanks & Regards,
    Sheshu Kumar Inguva.

  7. #7
    Registered User
    Join Date
    Aug 2008
    Location
    India
    Posts
    39

    Re: UDP connection to server working on emulator but not on device !

    Hi,

    I am trying to make a UDP Connection to "Server". On Emulator it is working fine(server recieves data), when I try it on N82 it prompts for selecting IAP, but the Server is not recieving anything. I have given it Capability-"NetworkServices" in MMP.
    Anyone had any clue what can be the problem. Here is the Code:

    Code:
    iSocket = new RSocket();
    	//Address to send UDP
    	TSockAddr iSendAddr(TInetAddr(INET_ADDR(72,29,81,250), 4568));
    	
    	User::LeaveIfError( iSocketServ.Connect());
    
    	User::LeaveIfError(iSocket->Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp)); 
    	
    	
    	iSocket->SendTo(_L8("Data to send"),iSendAddr,0,iStatus);
    	User::WaitForRequest(iStatus);
    Thanks in Advance,
    Rakesh

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

    Re: UDP connection to server working on emulator but not on device !

    It can be anything. Starting with a firewall for example.

Similar Threads

  1. How to bind UDP server sockets?
    By mimo099 in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2004-10-15, 19:31
  2. Gauge to monitor progress not working :(
    By mattsaccount in forum Mobile Java General
    Replies: 1
    Last Post: 2004-05-17, 02:07
  3. Open connection to the right virtual server
    By MrPatol in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2003-11-21, 21:21
  4. How to test the http connection on the real device ?
    By vhkrishna in forum Mobile Java General
    Replies: 1
    Last Post: 2002-07-26, 07:27

Posting Permissions

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