×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    70

    Unhappy Using EchoSocketEngine Example is not as Easy

    Hi, i started to use this example because it already deal with Sockets, but just saw that this example was meant to be a DLL, just before i figure it out, i made it work with my programm on the emulator, just an import of the Header on my own object and the apropiate calls, then i tried in the phone, but my surprise was that it didn't work, i found that it connect to the server ip i set, but fail on write over the socket, not exactly the iSocket instance on the engine but a method before, on the Writer object, the Write Method, it is a pointer it use to call the method who really do the write action, but it terminate the application just in the starting proccess.

    if i comment that line it works nice on the phone, but obviusly it doesn't send anything

    My question is, if that Example was made to be a DLL how can i use it?, is there another way to use Sockets without an ActiveObject? so i can write on my Class the apropiate methods to connect, disconnect and write to a socket?, thank you

  2. #2
    Super Contributor
    Join Date
    Jul 2006
    Location
    Oulu, Finland.
    Posts
    1,174

    Re: Using EchoSocketEngine Example is not as Easy

    If you look in the SDK for Sockets Client API Classes, there are asynchronous methods available for sending and receiving data, also you should always consider use of active objects, although you can avoid the use of active objects by using different WaitForRequest functions (eg : User::WaitForRequest) but your program will stop execution to this point until the asynchronous request is completed and it may not behave as expected.

    More about Active objects can be found at :
    http://www.newlc.com/ActiveObjects.html
    http://www.newlc.com/Symbian-Active-...amework-A.html


    Difference between Active Object and Threads:
    http://wiki.forum.nokia.com/index.ph..._Active_Object

    Using Socket API:
    http://wiki.forum.nokia.com/index.ph...he_sockets_API

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    30

    Re: Using EchoSocketEngine Example is not as Easy

    You can use sockets, without using active objects, but that's not recommended at all for real world applications, the only exception could be for test code...

    Anyway, here's how you'd use it synchronously. Note error checking is disabled for simplicity!

    // Assume sock is an RSocket instance
    _LIT(KConnectAddr, "192.168.0.1");
    const TUint port = 80;
    TInetAddr addr(port);
    addr.Input(KConnectAddr);

    // Connect to remote peer first
    TRequestStatus status;
    sock.Connect(addr, status);
    User::WaitForRequest(status);

    // Connected, lets exchange data...

    TBuf<6> buf;
    _LIT(KHello, "Hello!");
    sock.Write(buf, status);
    User::WaitForRequest(status);

    // Data written, now recv some data from remore peer...
    TSockXfrLength len;
    sock.RecvOneOrMore(buf, 0, status, len);
    User::WaitForRequest(status);

    ...

  4. #4
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    70

    Question Re: Using EchoSocketEngine Example is not as Easy

    Hi, thanks for the help, im now using a simple Active Object but im now getting the Kern Exec 0 error, i read this means the Kernel Executive cant find an object in the object index for the current process.

    I've checked my object against the one in the examples you gave me and can't see where i'm wrong the code i use is as fallows
    ---------------------------------------------------------------

    #include "Sender.h"

    CSender::CSender() :
    CActive(EPriorityStandard)
    {
    CActiveScheduler::Add (this);

    }
    ;

    CSender* CSender::NewL()
    {
    CSender* self = NewLC ();
    CleanupStack::Pop ();
    return self;
    }
    ;

    CSender* CSender::NewLC()
    {
    CSender* self = new(ELeave) CSender;
    CleanupStack::PushL (self);
    self->ConstructL ();
    return self;
    }
    ;

    void CSender::ConstructL()
    {

    iWriteStatus = EWaiting;

    // Open channel to Socket Server
    User::LeaveIfError (iSocketServ.Connect ());
    // Open a TCP socket
    User::LeaveIfError (iSocket.Open (iSocketServ, KAfInet, KSockStream,
    KProtocolInetTcp));

    }

    void CSender::ConnectL(TUint32 aAddr, TUint port)
    {

    iAddress.SetPort (port);
    iAddress.SetAddress (aAddr);
    iSocket.Connect (iAddress, status);

    }
    ;

    CSender::~CSender()
    {
    DoCancel ();
    }

    void CSender:oCancel()
    // Cancel asychronous write request
    {
    iSocket.CancelWrite ();
    }
    ;

    void CSender::RunL()
    // Active object request complete handler
    {
    if ( status == KErrNone)
    {
    switch (iWriteStatus)
    {
    // Character has been written to socket
    case ESending:
    iWriteStatus = EWaiting;
    break;
    // Request timed out
    case ETimedOut:
    break;
    default:
    ;
    };
    }
    else
    {
    // Error: pass it up to user interface

    }
    }

    void CSender::IssueWrite(const TDes &aText)
    // Write a data to a stream socket
    {
    // Set up buffer
    iBuffer.SetLength (0);
    iBuffer.Append (aText);
    iBuffer.Append (_L("\n"));
    iSocket.Write (iBuffer, iStatus);
    // Request timeout
    SetActive ();
    iWriteStatus = ESending;
    }
    ;

    if you can see what i can't please tell me, thank you
    Last edited by xchewy; 2008-04-28 at 23:07.

  5. #5
    Super Contributor
    Join Date
    Jul 2006
    Location
    Oulu, Finland.
    Posts
    1,174

    Re: Using EchoSocketEngine Example is not as Easy

    There are few things wrong with your code:

    1) You should never call DoCancel directly, call Cancel() instead, because its implemented by the base class and which checks for the active outstanding request and cancels if any, nothing otherwise

    2) void CSender::ConnectL(TUint32 aAddr, TUint port), here you have not marked this request as active, you should use SetActive() after issuing asynchrounous call iSocket.Connect (iAddress, status);

    3) Also use iStatus which is member of CActive , what is status used in iSocket.Connect (iAddress, status);

    4) Again use iStatus instead,
    void CSender::RunL()
    // Active object request complete handler
    {
    if ( status == KErrNone)
    {
    ...
    }
    Last edited by vasant21; 2008-05-06 at 20:03.

  6. #6
    Super Contributor
    Join Date
    Jul 2006
    Location
    Oulu, Finland.
    Posts
    1,174

    Re: Using EchoSocketEngine Example is not as Easy

    Can you also show me your header for the same?

Similar Threads

  1. Easy way to create preinstall application (PA from SA)
    By Leanid in forum Symbian Tools & SDKs
    Replies: 4
    Last Post: 2008-07-14, 09:00
  2. Newbie! easy BT question - can anyone help?
    By marquk in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2006-07-16, 22:12
  3. Plz tell me easy method to cut image from the strip
    By mwm786 in forum Mobile Java General
    Replies: 1
    Last Post: 2005-02-01, 10:12
  4. Easy way to send sis file to remote phone
    By jkekoni in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2004-05-31, 06:39
  5. agnapii.h -> Easy interface to Agenda model?
    By kwokwahon in forum Symbian
    Replies: 1
    Last Post: 2002-07-03, 10: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
  •  
×