Archived

This forum has been archived. Please start a new discussion on GitHub.

About Ice.RetryIntervals and client information

Hi all!
I am new in ICE and want to transport files with it.
I set Ice.RetryIntervals=0 10 20, expecting the client will retry three times when the server is down. But in fact when the server was down, the client retried unlimitedly. Can you tell me what's the matter?
On the other hand, I want to know whether the server can get the client's information such as IP when it is connected except the client provides it as the parameter of call.
Thank you very much!

Comments

  • But I need help! What I want is simple:
    1)When the client can't connect to the server because of any reason, for example, the network is broken, the server isn't running, the server shutdown suddenly, etc., the client can retry certain times and then stop connecting and throw an exception.
    2)When the client run a RPC, the server can get the client's information such as IP and port, given that the client dosen't provide it explicitly.
    Anyone can tell me what I should do? Thanks a lot!
  • The first thing to try is to enable Ice.Trace.Retry=2 and Ice.Trace.Network=2for both client and server. This will allow you to see connection establishment and closure, and to follow the rety behavior. I suspect that the server might accept the connection but then close (orderly) for some reason.

    Also, what version/language are you using?

    Cheers,

    Michi.
  • Thanks michi!
    I use Ice-3.2.1/C++ and my code is like this:

    //TransferFile.ice
    module File
    {
    sequence<byte> byteSeq;

    interface TransFile
    {
    void SaveFile(byteSeq buf, int len, string filename);
    };
    };

    //Client.cpp
    #include <Ice/Ice.h>
    #include <fstream>
    #include "TransFile.h"

    using namespace std;
    using namespace File;

    const int SIZE = 100;

    int main(int argc, char *argv[])
    {

    if (argc != 2)
    {
    printf("Usage: %s Filename\n", argv[0]);
    return 1;
    }

    int status = 0;
    Ice::CommunicatorPtr ic;

    File::byteSeq buf;
    buf.resize(SIZE + 1);

    try
    {
    ic = Ice::initialize(argc, argv);
    Ice::ObjectPrx base = ic->stringToProxy("FileTransform:default -h 192.168.1.42 -p 10000");
    TransFilePrx transFiler = TransFilePrx::checkedCast(base);
    if (!transFiler)
    throw "Invalid Proxy";

    ifstream inFile("file");
    while (1)
    {
    inFile.read((char *)&buf[0], SIZE);
    if (inFile.gcount() == 0)
    break;
    transFiler->SaveFile(buf, inFile.gcount(), argv[1]);
    }
    inFile.close();
    }
    catch (const Ice::Exception &e)
    {
    cerr << e << endl;
    status = 1;
    }
    catch (const char *msg)
    {
    cerr << msg << endl;
    status = 1;
    }

    if (ic)
    ic->destroy();

    return status;
    }

    //Server.cpp
    #include <Ice/Ice.h>
    #include <fstream>
    #include <iostream>
    #include "TransFile.h"

    using namespace std;
    using namespace File;

    class TransFileI: public TransFile
    {
    public:
    virtual void SaveFile(const File::byteSeq &buf, int len, const string &filename, const Ice::Current &);
    };

    void TransFileI::SaveFile(const File::byteSeq &buf, int len, const string &filename, const Ice::Current &)
    {
    ofstream outFile(filename.c_str(), ios::app);
    outFile.write((char *)&buf[0], len);
    outFile.close();
    }

    int main(int argc, char *argv[])
    {
    int status = 0;
    Ice::CommunicatorPtr ic;

    try
    {
    ic = Ice::initialize(argc, argv);
    Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWithEndpoints
    ("SimpleFileTransform", "default -p 10000");
    Ice::ObjectPtr object = new TransFileI;
    adapter->add(object, ic->stringToIdentity("FileTransform"));
    adapter->activate();
    ic->waitForShutdown();
    }
    catch (const Ice::Exception &e)
    {
    cerr << e << endl;
    status = 1;
    }
    catch (const char *msg)
    {
    cerr << msg << endl;
    status = 1;
    }

    if (ic)
    {
    try
    {
    ic->destroy();
    }
    catch (const Ice::Exception &e)
    {
    cerr << e << endl;
    status = 1;
    }
    }

    return status;
    }

    //Ice_config
    Ice.RetryIntervals=0 5000 10000

    I run the code in such four conditions as follows:
    1)run the client but the server is not running(the host 192.168.1.42 is connected): the client will retry three times as I expected and then throw a ConnectionRefusedException;
    2)run the client but the host 192.168.1.42 is disconnected: the client will retry three times as I expected and then throw a ConnectionFailedException;
    3)run the client and server both but shutdown the server(ctrl+c) while transporting the file: the client will throw a ConnectLostException immediately without retry three times as I expected;
    4)run the client and server both but disconnect the host 192.168.1.42(for example, pull out the network cable): the client will wait for about 15 minutes and then throw a SocketException;

    In the first and second condition, the result is what I need, because they both retry three times as I configure; However, in the last two conditions, I also want the client retry three times as I configure but it doesn't. So can you tell me what is the matter? In what way can the client perform just as what I want in the last two conditions?

    Thanks again!
  • benoit
    benoit Rennes, France
    Hi,

    The invocation isn't retried in #3 because it's probably not safe to do so without violating at-most-once semantics, see At-Most-Once Semantics in the Ice manual for more information.

    In #4, you most likely get hangs because you don't use timeouts. In the case of an unreachable host, it can take few minutes for the TCP/IP stack to return with a connection failure condition. You should set Ice.Override.ConnectTimeout to a suitable value to not wait for so long.

    Cheers,
    Benoit.
  • Thanks Benoit! Thanks Michi! I know it.
    But I am glad if you can answer my second question that whether the servant can get the client's information(IP or port) by some means without the client providing it explicitly.