Home Help Center

about publisher&subscribe

terminateterminate Member Jone QuOrganization: iFisher CO.,LTDProject: Process Control System for Hot Furnace in Shandong
Hi:
I have an example,but it can't work correctly!

following is the code for publisher:
#include <Ice/Ice.h>
#include <IceStorm/IceStorm.h>
#include "Monitor.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
    Ice::CommunicatorPtr communicator = Ice::initialize(argc,argv);
    Ice::PropertiesPtr properties = communicator->getProperties();
    Ice::ObjectPrx base = communicator->stringToProxy ("IceStorm/TopicManager:tcp -p 9999");
    IceStorm::TopicManagerPrx topicManager = IceStorm::TopicManagerPrx::checkedCast(base);
    if(!topicManager)
    {
	cout << "Error" << ": invalid proxy" << endl;
	return EXIT_FAILURE;
    }
    IceStorm::TopicPrx topic;
    try {
	topic = topicManager->retrieve("Weather");
    }
    catch (const IceStorm::NoSuchTopic&) {
	cout << "Create a new topic!" << endl;
	topic = topicManager->create("Weather");
    }
   assert(topic);
   Ice::ObjectPrx pub = topic->getPublisher();
   if (!pub->ice_isDatagram())
	pub = pub->ice_oneway();
   Monit::MonitorPrx monitor = Monit::MonitorPrx::uncheckedCast(pub);
   Monit::Measurement m;
   m.tower = "Tower";
   m.windSpeed = 12.2;
   m.windDirection = 1;
   m.temperature = 22.9;
   return 0;
}
following is the code for subscriber:
#include <Ice/Ice.h>
#include <IceStorm/IceStorm.h>
#include "Monitor.h"
#include <IceUtil/UUID.h>
#include <iostream>
using namespace std;
class MonitorI : virtual public Monit::Monitor 
{
public:
	virtual void report(const Monit::Measurement& m,const Ice::Current&) 
	{
	}
};
int main(int argc, char* argv[])
{

    Ice::CommunicatorPtr communicator = Ice::initialize(argc,argv);
    Ice::PropertiesPtr properties = communicator->getProperties();

    Ice::ObjectPrx base = communicator->stringToProxy("IceStorm/TopicManager:tcp -p 9999");
    IceStorm::TopicManagerPrx topicManager = IceStorm::TopicManagerPrx::checkedCast(base);
    if(!topicManager)
    {
	cout << "Error" << ": invalid proxy" << endl;
	return EXIT_FAILURE;
    }
    Ice::ObjectAdapterPtr adapter =communicator->createObjectAdapter("MonitorAdapter");
    Monit::MonitorPtr monitor = new MonitorI();
    Ice::ObjectPrx prox = adapter->addWithUUID(monitor);
    IceStorm::TopicPrx topic;
    try {
	topic = topicManager->retrieve("Weather");
	IceStorm::QoS qos;
	topic->subscribe(qos, prox);
    }
    catch (const IceStorm::NoSuchTopic& e) {
	    cout << "Error" << ": " << e << " name: " << e.name << endl;
	    return 0;
    }
    adapter->activate();
    communicator->waitForShutdown();
    topic->unsubscribe(prox);
    return 0;
}
following is ice file:
module Monit{
	struct Measurement {
		string tower; // tower id
		float windSpeed; // knots
		short windDirection; // degrees
		float temperature; // degrees Celsius
	};
	interface Monitor {
	void report(Measurement m);
	};
};
following is my tow configuration files:
config_service:
IceBox.ServiceManager.Endpoints=tcp -p 9998
IceBox.Service.IceStorm=IceStormService,30:create --Ice.Config=config
Freeze.DbEnv.IceStorm.DbHome=db
config:
MonitorAdapter.Endpoints=tcp
IceStorm.TopicManager.Proxy=IceStorm/TopicManager:tcp -p 9999
IceStorm.TopicManager.Endpoints=tcp -p 9999
IceStorm.Publish.Endpoints=tcp
IceStorm.Trace.TopicManager=2
IceStorm.Trace.Topic=1
IceStorm.Trace.Subscriber=1
IceStorm.Trace.Flush=1
Ice.Trace.Network=2
IceStorm.Flush.Timeout = 2000


the error is:
After i start the publisher,when the application runs until at the point "monitor->report(m)",the error ocurs,it can't publish the message and the application stops.

the example i work is refers to the demo you supplied.

Comments

  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    What error precisely occurs? I assume the publisher is missing a line of code also, since it doesn't actually publish the event :)
  • terminateterminate Member Jone QuOrganization: iFisher CO.,LTDProject: Process Control System for Hot Furnace in Shandong
    error

    After starting the subscriber,I run the publisher,and this time error occurs,presenting a error box of Microsoft visual c++.
    The error accurs when to publish the message!!:confused::confused:
  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    I suspect you have mismatched the runtime library. That is you built with release mode and linked with the debug mode ice libraries, or vise-versa.
  • terminateterminate Member Jone QuOrganization: iFisher CO.,LTDProject: Process Control System for Hot Furnace in Shandong
    Thanks

    hi:
    it is OK now!
    but another error message occurs.
    When to run the publisher,it outputs the message followed:
    .\Proxy.cpp:779: Ice::TwowayOnlyException:
    operation `ice_isA' can only be invoked as a twoway request

    what can i do now??

    :eek:
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    You are probably using checkedCast() on a oneway proxy. This is not possible, you must use a twoway proxy for this.
  • terminateterminate Member Jone QuOrganization: iFisher CO.,LTDProject: Process Control System for Hot Furnace in Shandong
    It works well!!

    Thanks!!!!!!!!!!!
  • icestorm dosenot work properly!

    hi,everyone.I use the source codes written in the ice3.1.0 document.There are three files:Monitor.ice,Publisher.cp and Subscriber.cpp.They are about icestorm and topic.I compliled them and created the executable files:Publisher and Subscriber.I want to run them on two computers such as 192.168.14.7 192.168.14.23.I use the config files located in Ice3.1.0/demo/IceStorm/clock.But they did not work properly!In my opinion,there are something wrong with the config files.Please help me,how to config the IceBox and IceStorm.Thank you very much.
  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    Please don't post the same question twice. After you fill in your signature details can help you with your issue.
Sign In or Register to comment.