×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    22

    Client Socket Program Not Working in Symbian C++ GUI Application

    Hi All,

    I have written a client program using Symbian C++ and it seems like it is not connecting to the server listening on a certain IP address and port number. My code is written below. Does anyone know what is the problem?

    RSocket iSocket;
    RSocketServ iSocketServ;
    TInetAddr iAddr;
    TRequestStatus aStatus;

    const TText8* txt = (TText8*)_S("TCP Client Testing!");
    TBuf8<100> sbuf(txt);

    iAddr.SetAddress(INET_ADDR(192,168,237,167));
    iAddr.SetPort(72);

    TInt iReturn;

    iReturn = iSocket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp);

    iSocket.Connect(iAddr, aStatus);

    iSocket.Send(sbuf, 0, aStatus);

    Any help would be much appreciated. Thanks in advance!

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: Client Socket Program Not Working in Symbian C++ GUI Application

    Quote Originally Posted by phuawl View Post
    Hi All,

    I have written a client program using Symbian C++ and it seems like it is not connecting to the server listening on a certain IP address and port number. My code is written below. Does anyone know what is the problem?

    RSocket iSocket;
    RSocketServ iSocketServ;
    TInetAddr iAddr;
    TRequestStatus aStatus;

    const TText8* txt = (TText8*)_S("TCP Client Testing!");
    TBuf8<100> sbuf(txt);

    iAddr.SetAddress(INET_ADDR(192,168,237,167));
    iAddr.SetPort(72);

    TInt iReturn;

    iReturn = iSocket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp);

    iSocket.Connect(iAddr, aStatus);

    iSocket.Send(sbuf, 0, aStatus);

    Any help would be much appreciated. Thanks in advance!
    Are you Waiting for a asynchronous request to complete? Or implemented active object??

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    22

    Re: Client Socket Program Not Working in Symbian C++ GUI Application

    May I know the difference between a synchronous and an asynchronous request? I have not implemented active object.

    Thanks!

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

    Re: Client Socket Program Not Working in Symbian C++ GUI Application

    Synchronous: result is provided on return.
    Asynchronous: result is provided later (when the asynchronous service - often executed in a different process, server). On Symbian, you get such result either via some callback method, or in a TRequestStatus variable (that is the role of "aStatus").
    So as a minimal solution, you have to wait until the Connect completes, then also wait for the Send:
    Code:
    ...
    iSocket.Connect(iAddr,aStatus);
    User::WaitForRequest(aStatus); // this line completely blocks your code until connection succeeds or fails
    if(aStatus!=KErrNone)
    {
        // do something about the error
    }
    else
    {
        iSocket.Send(sbuf,0,aStatus);
        User::WaitForRequest(aStatus);
        // then you can also check the result in aStatus here
    }
    Active objects basically convert this sequential execution to a callback-based one.

  5. #5
    Super Contributor
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: Client Socket Program Not Working in Symbian C++ GUI Application

    Quote Originally Posted by phuawl View Post
    May I know the difference between a synchronous and an asynchronous request? I have not implemented active object.

    Thanks!
    I suggest you to learn Active objects.

    http://www.cs.uta.fi/research/theses...panen_Aapo.pdf

    http://wiki.forum.nokia.com/index.php/Active_objects

    http://wiki.forum.nokia.com/index.ph..._in_Symbian_OS

  6. #6
    Super Contributor
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: Client Socket Program Not Working in Symbian C++ GUI Application

    Also read about Active objects, since you are calling asynchronus method.

    http://www.cs.uta.fi/research/theses...panen_Aapo.pdf

    http://wiki.forum.nokia.com/index.ph..._in_Symbian_OS

  7. #7
    Registered User
    Join Date
    Mar 2009
    Posts
    22

    Re: Client Socket Program Not Working in Symbian C++ GUI Application

    I have added the line iReturn = iSocketServ.Connect(); to the code below and it works on the carbide.c++ emulator. The client code below is able to connect to the server socket listening on IP address 192.168.238.157 and port 72. However, the code does not work when the application is installed and run on the mobile phone with the mobile phone connected to the internet network. Does anyone know the reason?

    RSocket iSocket;
    RSocketServ iSocketServ;
    TInetAddr iAddr;
    TRequestStatus aStatus;

    const TText8* txt = (TText8*)_S("TCP Client Testing!");
    TBuf8<100> sbuf(txt);

    iAddr.SetAddress(INET_ADDR(192,168,238,157));
    iAddr.SetPort(72);

    TInt iReturn;

    iReturn = iSocketServ.Connect();

    iReturn = iSocket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp);

    iSocket.Connect(iAddr, aStatus);

    iSocket.Send(sbuf, 0, aStatus);

    Thanks!

Similar Threads

  1. Replies: 20
    Last Post: 2009-04-03, 07:36
  2. [moved] Doubt regarding Nokia Test Criteria for Symbian Cpp Application
    By sameerbkamble in forum Symbian Signed Support, Application Packaging and Distribution and Security
    Replies: 1
    Last Post: 2009-03-21, 08:23
  3. Can a Symbian C++ client program communicate with a program residing on a webserver ?
    By razas in forum Symbian Networking & Messaging (Closed)
    Replies: 21
    Last Post: 2007-11-19, 17:33
  4. SOCKET PROGRAMMING: Client can not connect to server...
    By simbiyan in forum Symbian Networking & Messaging (Closed)
    Replies: 5
    Last Post: 2007-04-22, 20:00
  5. Replies: 1
    Last Post: 2006-02-15, 07:56

Posting Permissions

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