×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Regular Contributor
    Join Date
    May 2007
    Location
    India
    Posts
    136

    TCP server packet receiving problem

    Hi All,

    I am new to Symbian and working on 9.1 and Series 60 SDK. I am creating a sample TCP client server application using Active object for emulator.

    The procedure for client server communication is as following
    1) TCP server socket is created.
    2) Once created it listen to incoming connect request.
    3) TCP client socket is created and try to connect to TCP server socket.
    4) TCP server creates a service socket and accept the connection request.
    5) TCP client sends packet on connected socket to TCP server
    6) Here TCP server socker does not get any packets. Its RunL function is never called.

    The code is shown below

    TCP CLIENT:
    _________________________________________________________________
    Socket creation and connecting code
    {
    //Destination port
    const TInt KEchoPort = 1234;
    //Destination ip address
    const TUint32 KInetAddr = INET_ADDR(127,0,0,1);
    //Destination addres as InetAddr format
    TInetAddr destAddr;

    //Connect Server Socket
    if( KErrNone != ssCli.Connect())
    {
    CEikonEnv::Static()->AlertWin(_L("Fail to Connect SerSocket"));
    }

    //Open client socket
    if( KErrNone != sockCli.Open(ssCli, KAfInet, KSockStream, KProtocolInetTcp))
    {
    CEikonEnv::Static()->AlertWin(_L("Fail to Open Client Socket"));
    }

    //Set destination address
    destAddr.SetFamily(KAfInet);
    destAddr.SetAddress(KInetAddr);
    destAddr.SetPort(KEchoPort);

    //Send packet but do not wait to let the task complete
    sockCli.Connect(destAddr,iStatus);
    //Changing the state of socket to Connecting
    iState = Connecting;
    SetActive();
    }
    RunL for client is called on successful connection to server

    Packet sending code:
    {
    TBuf8<256> iWrite(_L8("abcdefghijklmnopqrstuvwxyz"));
    //Send packet but do not wait to let the task complete
    sockCli.Send(iWrite,NULL,iStatus);
    //Changing the state of socket to Sending
    iState = Sending;
    SetActive();
    }
    RunL for client is called on successful packet sending.
    _________________________________________________________________

    TCP SERVER:
    _________________________________________________________________
    Socket creation and listening code
    {
    //Error number buffer
    TBuf<32> errNo;
    //Error code
    TInt errCode;
    //Destination port
    const TInt KEchoPort = 1234;
    //Destination ip address
    const TUint32 KInetAddr = INET_ADDR(127,0,0,1);
    //Destination addres as InetAddr format
    TInetAddr anAddr;

    //Connect Server Socket
    if( KErrNone != ssSer.Connect())
    {
    CEikonEnv::Static()->AlertWin(_L("Fail to Connect SerSocket"));
    }

    //Open client socket
    if( KErrNone != sockSer.Open(ssSer, KAfInet, KSockStream, KProtocolInetTcp))
    {
    CEikonEnv::Static()->AlertWin(_L("Fail to Open Client Socket"));
    }

    //Set source address to which client will bind
    anAddr.SetFamily(KAfInet);
    anAddr.SetAddress(KInetAddr);
    anAddr.SetPort(KEchoPort);

    CEikonEnv::Static()->AlertWin(_L("Binding"));
    //Bind socket to source address
    errCode = sockSer.Bind(anAddr);
    errNo.Num(errCode);
    CEikonEnv::Static()->AlertWin(errNo);

    if( KErrNone != errCode )
    {
    CEikonEnv::Static()->AlertWin(_L("Fail to Bind Socket"));
    }

    CEikonEnv::Static()->AlertWin(_L("Listening"));
    //Listen socket for incoming request
    User::LeaveIfError(sockSer.Listen(1));

    CEikonEnv::Static()->AlertWin(_L("Accepting"));
    //Aceepting request and creating a new service socket
    sockBlank.Open(ssSer);
    sockSer.Accept(sockBlank,iStatus);
    //Change the socket status to Accepting
    iState = Accepting;
    SetActive();
    }
    RunL for server is called on successful accepting of client request

    Packet receiving code:
    {
    sockBlank.Recv(iRecv,NULL,iStatus);
    //Change the socket status to Receiving
    iState = Receiving;
    SetActive();
    }
    This code is executed successfully. But no call back is received in RunL of server active object
    _________________________________________________________________

    Does anybody has observed such behavior? Please provide guidence to trace the issue.


    Thanks & Regards
    Rajat

  2. #2
    Regular Contributor
    Join Date
    Jan 2005
    Posts
    154

    Re: TCP server packet receiving problem

    Hi,

    I am facing the same problem as yours. i got some disappointing replies in the thread below
    http://discussion.forum.nokia.com/fo...d.php?t=108935
    i am still haunting on the chanmps here to help me get over it maybe you will be saved as well. so watch it out

    by teh way i dont think you are getting the IP address part for the server correct. you need to enquire about the proper address allocated to your server app by your operator using the GetIp() function in the link above. Also i think you need not to worry about the Ip address for the client. Just use KInetAddrAny.

    Best
    AF
    Last edited by abolfoooud; 2007-06-01 at 15:07.

  3. #3
    Regular Contributor
    Join Date
    May 2007
    Location
    India
    Posts
    136

    Re: TCP server packet receiving problem

    Hi,

    Thanks for the reply. I just want to know that use of IAP/Id is necessary while creating TCP server client application for Emulator. I am new to symbian so not sure for that.

    When i am creating an application to work in localhost 127.0.0.1 do i need to get the IP address? As i am able to connect to TCP server socket from TCP client but the packet send from client is not recevied by server.

    Please correct me if i am wrong.

    Thanks
    Rajat

  4. #4
    Registered User
    Join Date
    May 2007
    Posts
    3

    Re: TCP server packet receiving problem

    HI Rajat,

    Did you got the solution for he above problem.I too facing the same problem.TCP server socker does not get any packets. Its RunL function is never called.Though the server is able to send packets to client and also the server is notified when the client get's dis connected.But unable to get packets from Clint.I am using Cobain (Bluetooth communications API) framework (for Symbian9.x+ environment ) . The COBAIN site claims to have not tested the listening code properly but I did not found any problems with the logic as such.

    Please help me if you found solution for this similar problem.

    Thanks
    Yunus

  5. #5
    Registered User
    Join Date
    May 2007
    Posts
    3

    Re: TCP server packet receiving problem

    Hi,
    Any Nokia champion's can help here ? . I am using Series60 3rd Edition and using .NET 2003 with Carbide.vs. I am testing using the Emulator. Any special settingson the Emulator needs to be done to resolve the above problem.Expecting feedback from Nokia champions.

    Thanks
    Yunus

  6. #6
    Registered User
    Join Date
    May 2007
    Posts
    3

    Re: TCP server packet receiving problem

    Hi All,
    I got the solution for this problem.The issue was my wrong interpreatation of the API :
    void Read(TDes8 &aDesc, TRequestStatus &aStatus);

    Please read below documentation of this API:

    For a stream-interfaced sockets, the function only completes when the full amount of requested data has been received (or the connection breaks). This means when the descriptor has been filled to its maximum length (not its current length).

    i.e RunL will be called only after descriptor has been filled to its maximum length.

    Thanks
    Yunus

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,699

    Re: TCP server packet receiving problem

    That is correct. If you want to receive arbitrary-sized data chunks, you should better use RecvOneOrMore, and concatenate the pieces.

  8. #8
    Registered User
    Join Date
    Jun 2007
    Posts
    33

    Re: TCP server packet receiving problem

    hi all
    please help me.
    I am creating a sample TCP server.
    I use the code above and use "RecvOneOrMore",
    but i got a error "kern-exec 3" on the emulator.
    please tell me how to solve it?
    And someone can give me a complete example about tcp or udp server?

    thanks a lot

  9. #9
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,699

    Re: TCP server packet receiving problem

    If you initiate a search for word RSocket in the Examples and/or Series60Ex (or S60Ex) directory of your SDK, you will find something. For example Chat example in 3rd edition SDK-s.

  10. #10
    Registered User
    Join Date
    Jun 2007
    Posts
    33

    Re: TCP server packet receiving problem

    Thank you for your reply.
    The example I have looked.
    May you give me other examples??

    thanks a lot

Similar Threads

  1. Replies: 3
    Last Post: 2008-09-09, 04:53
  2. connecting problem with a server
    By mbicer00 in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2006-06-11, 17:54
  3. s40 real device problem connecting to server
    By melas21 in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2004-06-09, 23:23
  4. Problem Starting the server
    By Nokia_Archived in forum WAP Servers
    Replies: 1
    Last Post: 2002-05-14, 18:03
  5. Web server problem
    By Nokia_Archived in forum WAP Servers
    Replies: 2
    Last Post: 2002-05-14, 11:19

Posting Permissions

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