×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    19

    Question Socked Server class - undefined reference to `RSocket::

    Hi there,

    I'm a very beginner in Symbian C++ and searching now for some hours for a solution but I do not find anything in the forum or in the wiki (http://wiki.forum.nokia.com/index.php/Active_object , http://wiki.forum.nokia.com/index.ph...he_sockets_API)

    I want to create a new Class (CServer). With the help of this class I want to make a streamed Socket Server, whereas a client offers data over the socket. The Class should be set up as CActive Object to get some continous action into the system.

    Below there is the code of the headerfile. When I create a new instance of the Server I do that this way:

    Code:
    CServer* iServerSocket=CServer::NewL(EPriorityHigh);
    later on I get data in randomly and want to provide it via the streamed socket server:
    Code:
    TBuf8<255> data; //atm it's not important what's in the data             //variable
    iServerSocket->SendData(data);
    Code:
    #ifndef __SERVER_H__
    #define __SERVER_H__
    
    #include <es_sock.h>
    #include <e32base.h>
    #include <in_sock.h>
    #include <e32cons.h>
    
    class MServerObserver{
    public:
    	virtual void HandleRequestCompleted(TInt aError) = 0;
    };
    
    class CServer: public CActive {
    
    enum iState{
    	EWaiting,
    	ESending,
    	EConnecting,
    	EConnected,
    };
    
    public:
        
    	static CServer* NewL(TInt aPriority);
        ~CServer();
    	void ReceiveData();
    	void SendData(TBuf8<255>& aData);
    
    //    void DoAsyncAction(MServerObserver* aObserver);
        
    protected:
    	// inherited from CActive
    	void RunL();
    	void DoCancel();
    	TInt RunError(TInt aError);
     
    private:
    	
    	CServer(TInt aPriority);
    	void ConstructL();
    	void StartEngineL (void);
    	
    	RSocketServ iSession;
        RSocket     iListen, iSocket;
    
    private:
    
        TInetAddr iAddr;
        TBuf8<255> iData;
        MServerObserver* iObserver; // Observer
        // observer erben, methoden implementieren (callback methoden)
    };
    
    #endif // __SERVER_H__

    Basically I get no errors, except 23 of them, all are located in the Server.cpp.text+0x38): undefined reference to `RSocketServ:RSocketServ()'

    orange one is different for each iSession, iListen, iSocket object depending on the method I call up.

    I hope it's clear which problem I have and maybe someone is able to tell me where my failures are

    -db

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

    Re: Socked Server class - undefined reference to `RSocket::

    "Undefined reference" is a linker error, you have to add the necessary .lib files to your project (in the .mmp file). Just search for RSocket, RSocketServ (and for any other class which pops up) in the SDK Help, the containing library is listed on the beginning of their help page.

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    19

    Smile Re: Socked Server class - undefined reference to `RSocket::

    THX for the fast reply

    This SDK help is very nice, thx again for the advice.

    Solution:

    esock.lib, esocksvr.lib and insock.lib have been missing in the .mmp file

  4. #4
    Registered User
    Join Date
    Jun 2008
    Posts
    19

    Unhappy Re: Socked Server class - undefined reference to `RSocket::

    Well, after working around a few days with my concept I have to ask for the solution because I really do not understand how to use the ActiveC Objects correctly. I get Panics and never reach the RunL method. Would be great if someone could have a look into the code and tell me what I do wrong.

    The Application is called ServerExample
    I want to createa Socket where I can send data which I get in Symbian C++, to a Java application, Java part is working and I get already the data I want to send, but the connection does not really work.

    I create the Server in the ConstructL of the ServerExampleContainer:
    PHP Code:
    iServerSocket=CServer::NewL(EPriorityHigh); 
    so far I hope everything works as it should, and a connection to the Symbian Server should be established.

    As far as I know the Active Objects waits until it was "startet". I have a menu option and by pressing it the following method is called:
    PHP Code:
    iServerSocket->DoAsyncAction(); 
    But the programm aborts with Panic: ServerExmaple E32User-CBase 46

    when I want to set Object Active:

    PHP Code:
    void CServer::DoAsyncAction(/*MServerObserver& aOberserver*/){
        
    //__ASSERT_ALWAYS(!IsActive(), User::Panic(KMyActivePanic, EAlreadyActive)); 
        //__ASSERT_ALWAYS(_Observer, User::Panic(KMyActivePanic, ENoObserver)); 
        
    iState=EStartSystem;
        
    //iObserver->ToState( ELookingUpIP );
        
    [U]SetActive();[/U// Starting the active sheduler?

    So I do not really understand what I should do, I hope someone can help me



    PHP Code:

    #include "Server.h"

    // Two Phase Constructor
    CServerCServer::NewL(TInt aPriority/*,MServerObserver& aOberserver*/){
        
    CServerself = new (ELeaveCServer(aPriority/*, aOberserver*/);
        
    CleanupStack::PushL(self);
        
    //iObserver=aOberserver;
        
    self->ConstructL();
        
    CleanupStack::Pop();
        return 
    self;
    }

    // Second-phase constructor
    void CServer::ConstructL(){
        
    // Connect to Symbian Socketserver
        
    User::LeaveIfError(iSocketServer.Connect());
        
    // Creating a listening socket for incommin Java connections.
        
    User::LeaveIfError(iListen.Open(iSocketServerKAfInet,KSockStreamKProtocolInetTcp));
        
        
    // Add self to active scheduler
        
    CActiveScheduler::Add(this);
    }

    // Constructor and destructor
    CServer::CServer(TInt aPriority/*,MServerObserver& aNotify*/)
    CActive(aPriority)/*,iNotify(aNotify)*/
    {}

    CServer::~CServer(){
        if(
    IsAdded()){
            
    Deque(); // calls also Cancel()
        
    }
    }

    void CServer::DoCancel(){
        
    Reset();
        
    iSocketServer.Close();
        
    iListen.Close();
        
    iSocket.Close();
    }

    void CServer::DoAsyncAction(/*MServerObserver& aOberserver*/){
        
    //__ASSERT_ALWAYS(!IsActive(), User::Panic(KMyActivePanic, EAlreadyActive)); 
        //__ASSERT_ALWAYS(_Observer, User::Panic(KMyActivePanic, ENoObserver)); 
        
    iState=EStartSystem;
        
    //iObserver->ToState( ELookingUpIP );
        
    SetActive(); // Starting the active sheduler?
    }

    //active sheduler
    void CServer::RunL(){
        
    // add a bit of error checking
        
    User::LeaveIfError(iStatus.Int()); // handle error in RunError (Whatever that means)
        
        
    switch(iState){
            case 
    EStartSystem:{
                if(
    iState == KErrNone){
                    
    Connect();
                    
    SetActive();
                }else{
                    
    //iObserver->Cancelled( iMsgBuf );
                    
    Reset();
                }
                break;
            }

            case 
    EConnecting:{
                if(
    iState == KErrNone){
                    
    iState EWriting;
                    
    //iObserver->ToState( EWriting );
                    
    TBuf8<255data;
                    
    data.Append('b');
                    
    data.Append('l');
                    
    data.Append('u');
                    
    data.Append('b');
                    
    data.Append('b');
                    
    data.Append('\n');
                    
    iSocket.Send(data0iStatus);
                    
    SetActive();
                }else{
                    
    //iObserver->Cancelled( iMsgBuf );
                    
    Reset();
                }
                break;
            }
        }

        
    // error condition
        //iObserver->HandleRequestCompleted(KErrNone);
        //SetActive();
    }

    void CServer::Connect(){
        
    iState EConnecting;
        
    //iObserver->ToState( EConnecting );
        /* The second (blank) socket is required to
           build the connection & transfer data.
           Bind the listening socket to the required
           port.*/
        
    iAddr.SetAddress(INET_ADDR(127,0,0,1));
        
    iAddr.SetPort(4949);
        
    User::LeaveIfError(iListen.Bind(iAddr));
        
    // Listen for 2 incoming connections...
        
    iListen.Listen(2);
        
    User::LeaveIfError(iSocket.Open(iSocketServer));
        
    // and accept an incoming connection.
        // On connection, subsequent data transfer will
        // occur using the socket iSocket
        
    iListen.Accept(iSocketiStatus);
    }


    void CServer::Reset(){
        switch (
    iState)
            {
            case 
    EConnecting:
                
    iSocketServer.Close();
                
    iListen.CancelAll();
                
    iListen.Close();
                break;
            }
        
    iState ENotConnected;
    }

    TInt CServer::RunError(TInt aError){
        
    //iObserver->HandleRequestCompleted(aError);
        
    return KErrNone;


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

    Re: Socked Server class - undefined reference to `RSocket::

    In case of implementing an Active Object,
    Code:
    iSomeServiceProvider::DoSomething(...,iStatus,...);
    and
    Code:
    SetActive();
    must appear in pairs.
    So this is the only proper usage in your code:
    Quote Originally Posted by ---___db___--- View Post
    iSocket.Send(data, 0, iStatus);
    SetActive();
    }
    Unfortunately it is still improper, since "data" is a local variable, and you should never pass local variables to asynchronous services. The word "asynchronous" means that the given service will use the passed variable later - when it will not exist actually, resulting in strange panics.

  6. #6
    Registered User
    Join Date
    Jun 2008
    Posts
    19

    Re: Socked Server class - undefined reference to `RSocket::

    Perfect explanation Works perfectly!

    Didn't know that the SetActive() must be paired with iStatus flag methods.

    and that I can not use local variables make sense and is a very good tip, I'm sure I would have run into troubles withouth the advice

    Thank you very much!

  7. #7
    Registered User
    Join Date
    Jun 2008
    Posts
    19

    Re: Socked Server class - undefined reference to `RSocket::

    And again there is a question which is unsolvable by seaching.

    After building the server, I want to send continously data over the socket. For that action I created following method, which will be called a few times in one second:

    PHP Code:
    void CServer::SendData(TBuf8<255>& aData){
        
    iData.Copy(aData);
        
    //iState=ESending;
        
    iSocket.Send(iData0iStatus);
        
    SetActive();

    The application just finishes and i do not which panic is called, because I use the Sensor API which is not debugable in the editor

    Does anyone have a suggestion what I could do, that the send function will work?

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

    Re: Socked Server class - undefined reference to `RSocket::

    Do not worry, panics are also available on the device, just they are hidden by default. Check http://wiki.forum.nokia.com/index.ph...ded_panic_code
    A side note about your code snippet: when you are accepting descriptors as an argument of a method, it is practical to use one of the descriptor superclasses:
    - "void CServer::SendData(const TDesC8& aData)" would accept all possible descriptors - even literals declared with _LIT8 or defined in-place using _L8
    - and if you want to write something to the descriptor (so it is an output argument): "void CServer::SendData(const TDes8& aData)", accepting all kind of modifiable descriptors

  9. #9
    Registered User
    Join Date
    Jun 2008
    Posts
    19

    Re: Socked Server class - undefined reference to `RSocket::

    THX

    Works very well now and also the tip for the panics was very usefull

  10. #10
    Registered User
    Join Date
    Jun 2008
    Posts
    19

    Re: Socked Server class - undefined reference to `RSocket::

    BTW is there a methode to start a java application right out of the running symbian application?

    something like when I push back the application to the background:

    PHP Code:
    RWsSession wsSession;
                
    wsSession.Connect();
                
    TApaTaskList taskList(wsSession);
                
    TApaTask task taskList.FindApp(_L("SlidersEdge"));
                if (
    iBackgroundtask.BringToForeground();
                else 
    task.SendToBackground();
                
    iBackground = !iBackground;
                
    wsSession.Close();
                
    iIsBackRepeated ETrue
    As far as I know the application can manage other symbian applications with that sort and the UID, but is that also possible for midlets?


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

    Re: Socked Server class - undefined reference to `RSocket::

    Search in the Wiki and/or simply read into the DiBo... A similar question from 1.5 hours ago: http://discussion.forum.nokia.com/fo...ad.php?t=82870

  12. #12
    Registered User
    Join Date
    Jun 2008
    Posts
    19

    Re: Socked Server class - undefined reference to `RSocket::

    oh thx, seached already a few hours in the morning Must have overseen that.

Similar Threads

  1. Error Error where are u ??
    By Abhishek_karmakar in forum Symbian
    Replies: 14
    Last Post: 2008-10-20, 09:29
  2. [moved] HELP! Phone Debug (GCCE)
    By joseph.m in forum Symbian
    Replies: 18
    Last Post: 2008-07-14, 10:42
  3. Undefined reference to non-virtual thunk (SDK>9.1)
    By Sectoid in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2008-01-16, 08:12
  4. Exceptions while loading application
    By avinash_rs in forum Mobile Java General
    Replies: 0
    Last Post: 2003-06-09, 10:53

Posting Permissions

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