×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    13

    Socket Programming Connect bind error

    Hi,
    I am new to Symbian world. I really stuck with socket programming. I was doing simple client/server program. When I execute the Server program, I am getting error in the accept call. It is not waiting for any request to accept. That is why I have put the user::waitforrequest()

    When I execute the client program it gives binding error 10048.

    FYI: I am running two programs from same carbide window.

    Here is my questions:
    1. Why accept call does not block for the request to accept (may i am comparing unix socket programming, if rectify me concept)
    2. In the connect we never bind, still why we are getting the binding error.
    3. In my code I have given the port number 8100, but bind error gives the port number as 3651, I have not got why the port number is changed.


    really I am confused, is it I need to run both program 2 different carbide C++, or am making any mistake in the code.
    TInetAddr iAddr;
    RSocketServ iSocketServ;
    RSocket iSocket;
    RSocket iAccept;
    const TUint32 KInetAddr = INET_ADDR(127,0,0,1);

    iAddr.SetAddress(KInetAddrAny);
    iAddr.SetPort(8100);
    TRequestStatus iRequestStatus;

    // Add to scheduler
    TInt iReturn = iSocketServ.Connect();
    if(iReturn != KErrNone)console->Write(_L("connected to RsocketServer"));

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

    if(iReturn != KErrNone) console->Write(_L("open the socket\n"));
    iReturn = iSocket.Bind(iAddr);
    if(iReturn != KErrNone)console->Write(_L("Bind is successful\n"));
    iReturn = iSocket.Listen(20);
    if(iReturn != KErrNone)console->Write(_L("Listening successful\n"));
    iReturn = iAccept.Open(iSocketServ);
    if(iReturn != KErrNone)console->Write(_L("Blank Socket is created"));
    iSocket.Accept(iAccept,iRequestStatus);
    if(iRequestStatus.Int() != KErrNone)console->Write(_L("Success Accept\n"));
    User::WaitForRequest(iRequestStatus);
    console->Write(_L("Hello, world!\n"));
    console->Write(_L("Hello, world!\n"));


    Client:

    LOCAL_C void MainL()
    {
    //
    // add your program code here, example code below
    //
    RSocketServ iServSocket;
    RSocket iSocket;
    TRequestStatus aStatus;

    TInetAddr destAddr;

    destAddr.SetAddress(INET_ADDR(127,0,0,1));
    destAddr.SetPort(8100);


    iServSocket.Connect();
    User::LeaveIfError(iSocket.Open(iServSocket,KAfInet,KSockStream,KProtocolInetTcp));
    iSocket.Connect(destAddr,aStatus);
    if(aStatus.Int()!=KErrNone) console->Write(_L("Error connecting socket...\n"));
    console->Write(_L("Hello, world!\n"));
    }

    LOCAL_C void DoStartL()
    {
    // Create active scheduler (to run active objects)
    CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
    CleanupStack::PushL(scheduler);
    CActiveScheduler::Install(scheduler);

    MainL();

    // Delete active scheduler
    CleanupStack::PopAndDestroy(scheduler);
    }


    Here is piece of code of client and server program:

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

    Re: Socket Programming Connect bind error

    Since you can not easily have two Carbides executing two emulators (if you have a single SDK only), the one Carbide-one emulator is a better configuration. Though switching between 2 console executables is not trivial; if you have a simple console->GetCh, it is going to be triggered by pressing the menu button.
    You may consider revising your if-s, sometimes you check for something==KErrNone, sometimes you check for something!=KErrNone. Instead of constant literals, you may rather want to use formatted descriptors, and simply print the code:
    Code:
    TInt iReturn = iSocketServ.Connect();
    if(iReturn != KErrNone)console->Write(_L("connected to RsocketServer"));
    could be
    Code:
    TBuf<100> buf;
    buf.Format(_L("iSocketServ.Connect: %d\n"),iSocketServ.Connect());
    console->Write(buf);
    Then you could de-code the error codes checking http://wiki.forum.nokia.com/index.php/Error_codes
    Also note that S60 3rd edition SDK-s come with Chat example, which contains a TCP/IP part too.

Similar Threads

  1. XMl Parser Implementation for Symbian
    By ittiam in forum Symbian
    Replies: 26
    Last Post: 2009-09-16, 05:26
  2. i cant build helloworld project
    By akhin in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 2
    Last Post: 2008-12-22, 12:38
  3. Bind socket error 10050
    By losqut in forum Bluetooth Technology
    Replies: 1
    Last Post: 2008-10-29, 17:21

Posting Permissions

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