Archived

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

problem about icestrom

my program can't execute successfully!
will terminate abnormally.
i don't know the reason.
and i can't run the demo clock successfully!
when i run it ,i will get the exception!
subscriber.exe: .\Network.cpp:542: Ice::ConnectFailedException:
connect failed: WSAETIMEDOUT

please give me some advices!
thanks~~


1.[config file]
#
# This property is used to configure the endpoints of the clock
# subscriber adapter.
#
monitor.Endpoints=tcp

#
# This property is used by the clients to connect to IceStorm.
#
IceStorm.TopicManager.Proxy=IceStorm/TopicManager:default -p 10000

#
# This property defines the endpoints on which the IceStorm
# TopicManager listens.
#
IceStorm.TopicManager.Endpoints=default -p 10000

#
# This property defines the endpoints on which the topic
# publisher objects listen.
#
IceStorm.Publish.Endpoints=default

#
# TopicManager Tracing
#
# 0 = no tracing
# 1 = trace topic creation, subscription, unsubscription
# 2 = like 1, but with more detailed subscription information
#
IceStorm.Trace.TopicManager=2

#
# Topic Tracing
#
# 0 = no tracing
# 1 = trace unsubscription diagnostics
#
IceStorm.Trace.Topic=1

#
# Subscriber Tracing
#
# 0 = no tracing
# 1 = subscriber diagnostics (subscription, unsubscription, event
# propagation failures)
#
IceStorm.Trace.Subscriber=1

#
# Flush Tracing (for batch mode transfer flushing)
#
# 0 = no tracing
# 1 = trace activity of flusher thread
#
IceStorm.Trace.Flush=1

#
# Amount of time in milliseconds between flushes for batch mode
# transfer. The minimum allowable value is 100ms.
#
IceStorm.Flush.Timeout = 2000

2.[my programes]
///subscriber

using namespace std;
using namespace Storm;

int main( int argc ,char* argv[] )
{
Ice::CommunicatorPtr communicator;

//load file config
Ice::PropertiesPtr properties = Ice::createProperties();
properties->load("config");
communicator = Ice::initializeWithProperties(argc, argv, properties);

//get the property
const string proxyProperty = "IceStorm.TopicManager.Proxy";
string proxy = properties->getProperty(proxyProperty);
cout <<proxy << endl;

//to produce topicmanagerprx
Ice::ObjectPrx base = communicator->stringToProxy(proxy);
IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(base);


//produce adapter
//in config there is monitor.Endpoints=tcp
Ice::ObjectAdapterPtr adapter = communicator ->createObjectAdapter("monitor");

MonitorPtr monitor = new MonitorI;

//flag information
cout << "no1"<<endl;
/////////////////////

Ice::ObjectPrx base1 = adapter->addWithUUID(monitor);

IceStorm::QoS qos;
qos["reliability"] = "batch";

IceStorm::TopicPrx topic;
try
{
topic = manager->retrieve("weather");
topic->subscribe(qos,base1);
}
catch(const IceStorm::NoSuchTopic& e)
{
cout << "error"<<endl;
topic = manager->create("weather");
}

adapter -> activate();
communicator->waitForShutdown();
topic->unsubscribe(base1);
if(communicator)
{
try
{
communicator->destroy();
}
catch(const Ice::Exception& ex)
{
cerr << ex << endl;
}
}
return 0;
}
/////////////////////////////////////
//publisher

int main( int argc , char* argv[] )
{
Ice::CommunicatorPtr communicator;
////////
Ice::PropertiesPtr properties = Ice::createProperties();
properties->load("config");
communicator = Ice::initializeWithProperties( argc, argv, properties );

/////////
const string proxyProperty = "IceStorm.TopicManager.Proxy";
string proxy = properties->getProperty(proxyProperty);
cout <<proxy << endl;
if(proxy.empty())
{
cout <<"proxy is empty\n";
return EXIT_FAILURE;
}

//////////////
//the programe can't pass here
Ice::ObjectPrx base = communicator->stringToProxy(proxy);
IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(base);
/////////////////
///this flag don't appear
cout <<"produce manager " << endl;
if(!manager)
{
cout << " manager is empty\n";
return EXIT_FAILURE;
}
/////////////////
IceStorm::TopicPrx topic;
cout <<" retrieve " << endl;
try
{
topic = manager->retrieve("weather");
}
catch(const IceStorm::NoSuchTopic& e)
{
topic = manager->create("weather");
}

/////////////////////
Ice::ObjectPrx obj = topic->getPublisher();
if(!obj->ice_isDatagram())
{
obj = obj->ice_oneway();
}

/////////////////
MonitorPrx monitor = MonitorPrx::uncheckedCast(obj);
//////////////////
for( int i = 0 ; i < 10 ; ++i )
{
Measurement m ;
m.tower = "i";
m.windSpeed = i;
m.windDirection = i;
m.temperature = i;
cout << "report " << i << endl;
monitor ->report( m );
}

////////////////////////
if(communicator)
{
try
{
communicator->destroy();
}
catch(const Ice::Exception& ex)
{
cerr << ex << endl;
}
}

return 0;
}

Comments

  • benoit
    benoit Rennes, France
    The timeout exception might be caused by a network configuration issue. Could you run your subscriber with the command line option "--Ice.Trace.Network=1" and see to which IP address it tries to connect to? This should match the IP of the host running the IceStorm server.

    If this is a problem related to your network configuration, you can explicitly define the IP address the IceStorm server will listen to with the endpoint configuration properties, for example:
    #
    # This property is used by the clients to connect to IceStorm.
    #
    IceStorm.TopicManager.Proxy=IceStorm/TopicManager:default -p 10000 -h 192.168.0.10
    
    #
    # This property defines the endpoints on which the IceStorm
    # TopicManager listens.
    #
    IceStorm.TopicManager.Endpoints=default -p 10000 -h 192.168.0.10
    
    #
    # This property defines the endpoints on which the topic
    # publisher objects listen.
    #
    IceStorm.Publish.Endpoints=default -h 192.168.0.10
    

    Here, the IceStorm service will listen on the interface with the IP address 192.168.0.10.

    Hope this helps!

    Benoit.
  • I have modified the config as your said ,
    added my ip in it ,
    but it still doesn't work.
    still show me .
    subscriber.exe: .\Network.cpp:536: Ice::ConnectionRefusedException:
    connection refused: WSAECONNREFUSED

    subsrcriber.exe --Ice.Trace.Network=1
    show nothing more!

    and i don't know why my programe can't execute those codes successfully.
    //////////////
    //the programe can't pass here
    Ice::ObjectPrx base = communicator->stringToProxy(proxy);
    IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(base);



    thanks a lot for your rapid reply:)
  • benoit
    benoit Rennes, France
    Sorry, you should try with --Ice.Trace.Network=2 to see the connection attempt. Can you try to run your IceStorm service and the subscriber with this command line option and post the traces here?

    You should see on which IP address the IceStorm service is listening and also the IP address the subscriber is using to connect to the service.

    Benoit.
  • 202.198.30.96 is my ip.


    [ subscriber.exe: Network: trying to establish tcp connection to 202.198.30.96:10
    0000 ]
    [ subscriber.exe: Network: trying to establish tcp connection to 202.198.30.96:10
    0000 ]
    subscriber.exe: .\Network.cpp:536: Ice::ConnectionRefusedException:
    connection refused: WSAECONNREFUSED

    [ publisher.exe: Network: trying to establish tcp connection to 202.198.30.96:10
    000 ]
    [ publisher.exe: Network: trying to establish tcp connection to 202.198.30.96:10
    000 ]
    publisher.exe: .\Network.cpp:536: Ice::ConnectionRefusedException:
    connection refused: WSAECONNREFUSED


    the server and subscriber code :

    #include <Ice/Application.h>
    #include <IceStorm/IceStorm.h>
    #include <IceUtil/UUID.h>

    #include <ClockI.h>

    #include <map>

    using namespace std;
    using namespace Demo;

    class Subscriber : public Ice::Application
    {
    public:

    virtual int run(int, char*[]);
    };

    int
    main(int argc, char* argv[])
    {
    Subscriber app;
    return app.main(argc, argv, "config");
    }

    int
    Subscriber::run(int argc, char* argv[])
    {
    Ice::PropertiesPtr properties = communicator()->getProperties();



    const string proxyProperty = "IceStorm.TopicManager.Proxy";
    string proxy = properties->getProperty(proxyProperty);
    cout << appName() << " " << proxy<<endl;
    if(proxy.empty())
    {
    cerr << appName() << ": property `" << proxyProperty << "' not set" << endl;
    return EXIT_FAILURE;
    }

    Ice::ObjectPrx base = communicator()->stringToProxy(proxy);
    IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(base);
    if(!manager)
    {
    cerr << appName() << ": invalid proxy" << endl;
    return EXIT_FAILURE;
    }

    //
    // Gather the set of topics to which to subscribe. It is either
    // the set provided on the command line, or the topic "time".
    //
    Ice::StringSeq topics;
    if(argc > 1)
    {
    for(int i = 1; i < argc; ++i)
    {
    topics.push_back(argv);
    }
    }
    else
    {
    topics.push_back("time");
    }

    //
    // Set the requested quality of service "reliability" =
    // "batch". This tells IceStorm to send events to the subscriber
    // in batches at regular intervals.
    //
    IceStorm::QoS qos;
    qos["reliability"] = "batch";

    //
    // Create the servant to receive the events.
    //
    Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Clock.Subscriber");
    Ice::ObjectPtr clock = new ClockI();

    //
    // List of all subscribers.
    //
    map<string, Ice::ObjectPrx> subscribers;

    //
    // Add the servant to the adapter for each topic. A ServantLocator
    // could have been used for the same purpose.
    //
    for(Ice::StringSeq::iterator p = topics.begin(); p != topics.end(); ++p)
    {
    //
    // Add a Servant for the Ice Object.
    //
    Ice::ObjectPrx object = adapter->addWithUUID(clock);
    try
    {
    IceStorm::TopicPrx topic = manager->retrieve(*p);
    topic->subscribe(qos, object);
    }
    catch(const IceStorm::NoSuchTopic& e)
    {
    cerr << appName() << ": " << e << " name: " << e.name << endl;
    break;
    }

    //
    // Add to the set of subscribers _after_ subscribing. This
    // ensures that only subscribed subscribers are unsubscribed
    // in the case of an error.
    //
    subscribers[*p] = object;
    }

    //
    // Unless there is a subscriber per topic then there was some
    // problem. If there was an error the application should terminate
    // without accepting any events.
    //
    if(subscribers.size() == topics.size())
    {
    adapter->activate();
    shutdownOnInterrupt();
    communicator()->waitForShutdown();
    }

    //
    // Unsubscribe all subscribed objects.
    //
    for(map<string,Ice::ObjectPrx>::const_iterator q = subscribers.begin(); q != subscribers.end(); ++q)
    {
    try
    {
    IceStorm::TopicPrx topic = manager->retrieve(q->first);
    topic->unsubscribe(q->second);
    }
    catch(const IceStorm::NoSuchTopic& e)
    {
    cerr << appName() << ": " << e << " name: " << e.name << endl;
    }
    }

    return EXIT_SUCCESS;
    }
  • benoit
    benoit Rennes, France
    Is your IceStorm server running on this host and listening on the port 10000? Can you try to run IceStorm on your host with the following command line and see on which port it's listening to?
       icebox --Ice.Config=config_service --Ice.Trace.Network=1
    

    The config_service file is the configuration file for IceStorm from Ice-2.1.1/demo/IceStorm/clock.

    Benoit.
  • oh~
    the code is my need.
    thanks :)

    now~
    the server has been started .but when i run subscriber ,i got the exception.
    is it a config error?

    [ subscriber.exe: Network: trying to establish tcp connection to 202.198.30.96:1
    0000 ]
    [ subscriber.exe: Network: tcp connection established
    local address = 202.198.30.96:2909
    remote address = 202.198.30.96:10000 ]
    [ subscriber.exe: Network: attempting to bind to tcp socket 202.198.30.96:10000
    ]
    subscriber.exe: .\Network.cpp:404: Ice::SocketException:
    socket exception: WSAEADDRINUSE
    [ subscriber.exe: Network: shutting down tcp connection for writing
    local address = 202.198.30.96:2909
    remote address = 202.198.30.96:10000 ]
    [ subscriber.exe: Network: closing tcp connection
    local address = 202.198.30.96:2909
    remote address = 202.198.30.96:10000 ]
  • benoit
    benoit Rennes, France
    Hi,
    [ subscriber.exe: Network: attempting to bind to tcp socket 202.198.30.96:10000]
    subscriber.exe: .\Network.cpp:404: Ice::SocketException:
    socket exception: WSAEADDRINUSE
    

    This exception means that your subscriber couldn't listen on the port 10000 because it's already used. The IceStorm service is already listening on this port. You need to change the configuration of your subscriber (from the code above, I believe it's the monitor.Endpoints property) to listen on another port or a random port.

    Benoit.
  • thanks very much ~
    i have built it successfully!