Archived

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

how can i make server send string to client

hi,good afternoon:
printer.ice:
module Demo{
interface Printer
{
void printString(string s);
};
};


server.cpp:
#include <Ice/Ice.h>
#include <Ice/Ice.h>
#include <Ice/Application.h>
#include <Printer.h>
using namespace std;
using namespace Demo;
class PrinterI : public Printer {
public:
virtual void printString(const string & s,
const Ice::Current &);
};
void
PrinterI::
printString(const string & s, const Ice::Current &)
{
cout << s << endl;
}

class MyApp : public Ice::Application
{
public:
virtual int run(int, char*[]);
};

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


int MyApp::run(int argc, char* argv[])
{
Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Printer");
adapter->add(new PrinterI, Ice::stringToIdentity("printer"));
adapter->activate();
communicator()->waitForShutdown();
return EXIT_SUCCESS;
}



client.cpp:
#include <Ice/Ice.h>
#include <Ice/Application.h>
#include <Printer.h>
using namespace std;
using namespace Demo;

class HelloClient : public Ice::Application
{
public:
virtual int run(int, char*[]);
};


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

HelloClient app;
return app.main(argc, argv, "config");
}

int HelloClient::run(int argc, char* argv[])
{
Ice::PropertiesPtr properties = communicator()->getProperties();
const char* proxyProperty = "Printer.Proxy";
string proxy = properties->getProperty(proxyProperty);
if(proxy.empty())
{
cerr << argv[0] << ": property `" << proxyProperty << "' not set" << endl;
return EXIT_FAILURE;
}
PrinterPrx twoway = PrinterPrx::checkedCast(
communicator()->stringToProxy(proxy)->ice_twoway()->ice_timeout(-1)->ice_secure(false));
if(!twoway)
{
cerr << argv[0] << ": invalid proxy" << endl;
return EXIT_FAILURE;
}
string name = "jerry";
twoway->printString(name);
return EXIT_SUCCESS;
}



these code is make client send string(jerry) to server,server show this string

how can i modify this code that make server send string(XXXX) to client,client show this string.

thank you :o

Comments

  • benoit
    benoit Rennes, France
    Hi,

    Take a look at the demo/Ice/callback demo. This should give you some hints on how to get a server to callback on the client. Note that the client in this situation also acts as a server (see the Section 2.2.2 in the Ice manual for the definitions of the terms "client" and "server" in the context of an Ice application). Let us know if you need more information.

    Cheers,
    Benoit.
  • thank you very