×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    17

    Angry Socket connection not returning error code?

    I've got a modified version of the sockets example working, but I want to generate, or at least I expected to have some sort of error, when I tried to connect to a server that is not running.. I used the code

    iSocket.Connect(iAddress, iStatus);

    but no error was generated.. Urgent help is required... :-)

  2. #2
    Registered User
    Join Date
    Feb 2005
    Posts
    21
    Connect() is an asynchronous call. So you have to check iStatus in your RunL method. It will be either KErrNone or one of the system wide error codes.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    17
    Hi memleak, I forgot to add that I checked the iStatus parameter and got KErrNone, even when the server I'm trying to connect to is down. I thought this was weird.. Help :-)

  4. #4
    Registered User
    Join Date
    Feb 2005
    Posts
    21
    paste your code here

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    17
    Hi memleak, I forgot to add that I checked the iStatus parameter and got KErrNone, even when the server I'm trying to connect to is down. I thought this was weird.. Help :-)

  6. #6
    Registered User
    Join Date
    Feb 2005
    Posts
    21
    As I said, paste your code here.

  7. #7
    Registered User
    Join Date
    Dec 2004
    Posts
    17
    Here's the meat of the connection code, the message boxes is used for debugging on the device.. 6630. Essentially, I'm trying to connect over the internet using the vodafone internet IAP to a my local echo sever. I can connect Ok, but I still "seam" to be able t o connect even when my echo server is shut down? Thanks

    RConnection iRConn;
    RSocketServ iSocketServ;
    RSocket iSocket;


    void CExEngine::ConnectL()
    {
    // Initiate connection process
    if (iEngineStatus == ENotConnected)
    {

    //Open an RConnection on the Socket Server
    User::LeaveIfError(iRConn.Open(iSocketServ));

    TCommDbConnPref prefs;
    prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    prefs.SetDirection(ECommDbConnectionDirectionOutgoing);
    //prefs.SetIapId(basePrefs.iBearer.iIapId);
    prefs.SetIapId(0);


    // Start the Connection
    iRConn.Start(prefs,iStatus);
    ChangeStatus(ERConnStarting);
    iTimer->After(KTimeOut);

    SetActive();
    }
    }



    void CExEngine::ConnectL(TUint32 aAddr)
    {
    // Initiate attempt to connect to a socket by IP address
    if (iEngineStatus == ENotConnected)
    {
    // Open a TCP socket
    User::LeaveIfError(iSocket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp, iRConn));

    // Set up address information
    iAddress.SetPort(iPort);
    iAddress.SetAddress(aAddr);

    // Initiate socket connection
    iSocket.Connect(iAddress, iStatus);
    ChangeStatus(EConnecting);

    // Start a timeout
    iTimer->After(KTimeOut);

    SetActive();
    }
    }



    void CExEngine::RunL()
    {
    // Active object request complete handler.
    // iEngineStatus flags what request was made, so its
    // completion can be handled appropriately


    iTimer->Cancel(); // Cancel TimeOut timer before completion

    switch(iEngineStatus)
    {

    case ERConnStarting:
    // need to look up name using dns
    // Initiate DNS
    if (iStatus == KErrNone)
    {

    User::LeaveIfError(iResolver.Open(iSocketServ, KAfInet, KProtocolInetTcp, iRConn));
    // DNS request for name resolution
    iResolver.GetByName(iServerName, iNameEntry, iStatus);

    ChangeStatus(ELookingUp);
    // Request time out
    iTimer->After(KTimeOut);
    SetActive();
    }
    else
    {


    ChangeStatus(ENotConnected);
    Cancel();
    ReportErrorL(EDNSLookupFailed, iStatus.Int());
    }
    break;

    case ELookingUp:
    iResolver.Close();
    if (iStatus == KErrNone)
    {

    // DNS look up successful
    iNameRecord = iNameEntry();

    ChangeStatus(ENotConnected);
    ConnectL(TInetAddr::Cast(iNameRecord.iAddr).Address());
    }
    else
    {
    // DNS lookup failed

    ChangeStatus(ENotConnected);
    Cancel();
    ReportErrorL(EDNSLookupFailed, iStatus.Int());
    }
    break;

    case EConnecting:
    // IP connection request

    MsgBox(_L("CONNECTING-ENTERED"));
    if (iStatus == KErrNone)
    // Connection completed successfully
    {

    MsgBox(_L("CONNECTING-OK"));
    ChangeStatus(EConnected);
    // Get the time
    Read();
    }
    else
    {
    MsgBox(_L("COnnection Failed"));
    ChangeStatus(ENotConnected);
    Cancel();
    ReportErrorL(EConnectionFailed, iStatus.Int());
    }
    break;
    case EConnected:
    case EReading:
    {
    MsgBox(_L("READING::CONNECTED"));

    break;
    }

    default:
    {
    ChangeStatus(EDestroyed);
    MsgBox(_L("READING:EFAULT"));
    User::Panic(KPanicEngine, EBadStatus);
    break;
    }
    };
    }

  8. #8
    Registered User
    Join Date
    Feb 2005
    Posts
    21
    what's the address and port number your trying to connect to ?

  9. #9
    Registered User
    Join Date
    Dec 2004
    Posts
    17
    Hi memleak,

    I can't see how the port number and IP address affects not getting an error code if the server is not running. Have you had this happen to you before. From my knowledge of sockets, even if I tried to write to it, I should get an i/o exception, I don't even get this, Please educate :-)

  10. #10
    Registered User
    Join Date
    Dec 2004
    Posts
    17
    Has anyone tried using the symbian Tcp connection to blocked port. i.e iSocket.connect(iStatus); Make the connection to a real IP address but to a blocked port . Do you get an error ? I don't seam to one. Help :-)

  11. #11
    Registered User
    Join Date
    Dec 2004
    Posts
    17
    Has anyone tried using the symbian Tcp connection to blocked port. i.e iSocket.connect(iStatus); and using Rconnection. Make the connection to a real IP address but to a blocked port . Do you get an error ? I don't seem to one. Help :-)

  12. #12
    Registered User
    Join Date
    Aug 2003
    Posts
    16

    Socket Connect returns KErrNone even if server is not running

    Hi,

    I am also facing the same problem. I have defined two servers- primary and secondary. In case my app fails to connect to primary server, it can connect to secondary. But the problem is that anytime I call iSocket.Connect(), it rtuens immediately (I mean RunL is called immediately) with iStataus as KErrNone. It always return me KErrNone even if my server is not running. The strange thing is that it even doesn't time out. So my app just keep waiting for connect to finish.

    As per documentation the Connect should return with some error in RunL, but in reality it doesn't. Did you find some soultion for your problem.

    Thanks.

  13. #13
    Registered User
    Join Date
    Dec 2004
    Posts
    17
    The symbian rsocket.connect() API does not appear to inform yu about a succesful connection, instead, i believe it informs yu that an atempt at a connection has sucesfully started. I used a work around to solve my problem. The application I was working on was designed to handle enquire response data between the client and the server. So after I get the Kerrnon, I send an enqire data packet and if don't get a response within say 10 secs, I assume the connection is down.

Posting Permissions

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