×

Discussion Board

Results 1 to 13 of 13

Thread: UDP Client

  1. #1
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    123

    UDP Client

    Hi.
    I want to send data to server by UDP protocol. So I read this forum. And I wrote method thad send data, but have follow error :

    Code:
    `RSocketServ' undeclared (first use this function)
    . In all sources examples RSocketServ isn`t declared. It`s my method:

    Code:
    void CUDPHandler::SendData(TBuf<255> aIp, TUint8 aData[])
        {
        RSocketServ socketServ;
        User::LeaveIfError(socketServ.Connect());
        CleanupClosePushL(socketServ);
    
        // Open a socket
        RSocket socket;
        User::LeaveIfError(socket.Open (socketServ,KAfInet,KSockStream,KProtocolInetUdp));
        CleanupClosePushL(socket); 
        
        TInetAddr iAddress;
        iAddress.SetPort(8080);
        iAddress.SetAddress(KInetAddrAny);
        iAddress.Input(_L("192.168.1.2"));
        
        TBuf8<11> iBuffer;
        iBuffer.Zero();
        iBuffer.Append(_L("TestMessage"));
    
    
        User::LeaveIfError(socket.SetLocalPort(8080));
    
        socket.SendTo(iBuffer,iAddress,0,iStatus);
        SetActive();
        }
    Will that method send data to server?

    Regards

    Samos

  2. #2
    Super Contributor
    Join Date
    Nov 2004
    Posts
    1,009

    Re: UDP Client

    RsocketServ id declared in this ES_SOCK.H

    Try after including this.
    Regards,
    Shafali

  3. #3
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    123

    Re: UDP Client

    Yes, I included <es_sock.h> and <in_sock.h>. in my code i changet

    User::LeaveIfError(socket.Open (socketServ,KAfInet,KSockStream,KProtocolInetUDP));
    on
    User::LeaveIfError(socket.Open (socketServ,KAfInet,KSockStream,KProtocolInetTcp));

    But after that method emulator crash with code E32USER-CBase 71. Why?

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

    Re: UDP Client

    Undeclared stuff is related to missing #include-s.
    The bigger problem is that all of your variables are local ones, and you invoke an asynchronous request on them. Have you thought about what will happen with your socket, socketserver, address and buffer variables when you return from this method? So that is why all 4 components should be member variables of your CUDPHandler.

  5. #5
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    123

    Re: UDP Client

    Thanks wizard_hu_

    I can`t move that components to *.h file becouse I`ve got follow error:

    Code:
    empty array must be last class/struct member
    BTW. I changed my code and now it`s should send data to server (i hope som but i can`t check it yet ).

    Its all my code

    Code:
    #include "UDPHandler.h"
    #include <es_sock.h> 
    #include <in_sock.h>
    
    CUDPHandler::CUDPHandler()
    : CActive( CActive::EPriorityStandard )
        {
        CActiveScheduler::Add( this );
        }
    
    CUDPHandler::~CUDPHandler()
        {
        }
    
    CUDPHandler* CUDPHandler::NewLC()
        {
        CUDPHandler* self = new (ELeave) CUDPHandler();
        CleanupStack::PushL(self);
        self->ConstructL();
        return self;
        }
    
    CUDPHandler* CUDPHandler::NewL()
        {
        CUDPHandler* self = CUDPHandler::NewLC();
        CleanupStack::Pop(); // self;
        return self;
        }
    
    void CUDPHandler::ConstructL()
        {
    
        }
    
    void CUDPHandler::DoCancel()
        {
        
        }
    
    void CUDPHandler::RunL()
        {
        if (iStatus != KErrNone) 
            {
            TInt a=0;
            }
        else
            {
            TInt b =0;
            }
        }
    
    void CUDPHandler::SendData()
        {
        RSocketServ socketServ;
        TInt err;
        err = socketServ.Connect();
    //    CleanupClosePushL(socketServ);
    //    
        // Open a socket    
        RSocket socket;
        User::LeaveIfError(socket.Open (socketServ,KAfInet,KSockDatagram,KProtocolInetUdp));
    //    CleanupClosePushL(socket); 
    //    
        TInetAddr iAddress;
        iAddress.SetPort(8080);
        iAddress.SetAddress(KInetAddrAny);
        iAddress.Input(_L("192.168.1.150"));
        
        TBuf8<11> iBuffer;
        iBuffer.Zero();
        iBuffer.Append(_L("TestMessage"));
    
        socket.SetLocalPort(8080);
    
        TInt r;
        TRAP(r,socket.SendTo(iBuffer,iAddress,0,iStatus));
        SetActive();
    
        }
    Is thad code correct?

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

    Re: UDP Client

    I do not see any changes, and no, it is not correct.
    Check the snippets in http://discussion.forum.nokia.com/fo...d.php?t=179838 for example: none of the variables are declared locally.
    The error message uses a pretty clear wording: you probably tried to declare an array member without size - consider using a pointer instead (getting rid of it would be even better though).

  7. #7
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    123

    Re: UDP Client

    wizard_hu_ could you show me how to declare TInetAddr, RSocket and RSocketServ. I treid declared that members as pointer, but i have got same error.

    TInetAddr iAddress;
    RSocket socket;
    RSocketServ* socketServ;

    I now tham my problems are simply, but I`m Java developer, and symbian is a little difficult for me.

    Please help, becouse I have to do it today
    Last edited by samosnokia; 2009-09-18 at 08:12.

  8. #8
    Super Contributor
    Join Date
    Nov 2004
    Posts
    1,009

    Re: UDP Client

    Quote Originally Posted by samosnokia View Post
    wizard_hu_ could you show me how to declare TInetAddr, RSocket and RSocketServ. I treid declared that members as pointer, but i have got same error.

    TInetAddr iAddress;
    RSocket socket;
    RSocketServ* socketServ;

    I now tham my problems are simply, but I`m Java developer, and symbian is a little difficult for me.

    Please help, becouse I have to do it today

    // Declare the in your header file and use them in .cpp.
    TInetAddr iAddress;
    RSocket socket;
    RSocketServ socketServ;
    Regards,
    Shafali

  9. #9
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    123

    Re: UDP Client

    shafali, if I do as you wrote, then i get follow error "empty array must be last class/struct member". Wizard_hu_ say to use pointer, but when I do

    TInetAddr* iAddress;
    RSocket* socket;
    RSocketServ* socketServ;

    I have same error.

    Maybe I have to do something in construcotr?

  10. #10
    Super Contributor
    Join Date
    Nov 2004
    Posts
    1,009

    Re: UDP Client

    Quote Originally Posted by samosnokia View Post
    shafali, if I do as you wrote, then i get follow error "empty array must be last class/struct member". Wizard_hu_ say to use pointer, but when I do

    TInetAddr* iAddress;
    RSocket* socket;
    RSocketServ* socketServ;

    I have same error.

    Maybe I have to do something in construcotr?
    TInetAddr* iAddress;
    RSocket* socket;
    RSocketServ* socketServ;


    I am not asking you to craete pointer in header file.

    You can simple use them as

    TInetAddr iAddress;
    RSocket socket;
    RSocketServ socketServ;

    and keep your rest of code as it is.
    Regards,
    Shafali

  11. #11
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,688

    Re: UDP Client

    No, I was saying pointer instead of the array. My guess was that you declared something like "sometype x[];" in the middle of your header.

  12. #12
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    123

    Re: UDP Client

    TInetAddr iAddress[];//empty array must be last class/struct member
    RSocket socket[];//empty array must be last class/struct member
    RSocketServ socketServ[];//empty array must be last class/struct member

    same as

    TInetAddr iAddress[1];//empty array must be last class/struct member
    RSocket socket[1];//empty array must be last class/struct member
    RSocketServ socketServ[1];//empty array must be last class/struct member

    same as

    TInetAddr iAddress;//empty array must be last class/struct member
    RSocket socket;//empty array must be last class/struct member
    RSocketServ socketServ;//empty array must be last class/struct member

    I haven`t any other idea ;]

  13. #13
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    123

    Re: UDP Client

    Hi.
    I wrote method that send data by UDP. But now, my method send TBuf<255>. Is any way to send TUint8 data?

    I wrote this, but I`m not sure is it correct:

    Code:
    void CUDPHandler::SendData(TInetAddr aAddr, TUint8 aData[])
        {
        RSocketServ socketServ;
        TInt err;
        err = socketServ.Connect();
    
        // Open a socket    
        RSocket socket;
        User::LeaveIfError(socket.Open (socketServ,KAfInet,KSockDatagram,KProtocolInetUdp));
    
        TPtrC8 data((const TUint8*)aData, CRecord::RECORD_SIZE);
        socket.SendTo(data,aAddr,0,iStatus);
        SetActive();
    
        }
    Last edited by samosnokia; 2009-09-21 at 09:17.

Similar Threads

  1. how to use udp, for sending data server to client
    By acayir in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2006-08-02, 19:18
  2. Bluetooth client problem on games!
    By wmchan78 in forum Mobile Java Networking & Messaging & Security
    Replies: 6
    Last Post: 2006-03-22, 06:15
  3. udp client crashes on SendTo (S60)
    By Jeepy in forum Symbian
    Replies: 3
    Last Post: 2006-02-27, 08:05
  4. UDP server 'n' client
    By ddeveloper in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2005-05-30, 06:01
  5. Nokia Mobile VPN Client
    By marcyl in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2003-12-01, 14:47

Posting Permissions

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