The client source :
Code:
import Demo.*;
import java.util.*;
public class Client {
public static void main(String []args) {
Random random = new Random ();
Transmit trans;
String s = null;
int status = 0;
Ice.Communicator ic = null;
try {
ic = Ice.Util.initialize (args);
Ice.ObjectPrx base = ic.stringToProxy("hello:tcp -p 10000 -h 156.189.89.125");
Demo.HelloPrx hello = Demo.HelloPrxHelper.checkedCast(base);
if (hello == null) throw new Error("Invalid proxy");
hello.sayHello("Hello !!");
for (int i = 0; i < 3; i++) {
int a = random.nextInt();
double d1 = random.nextDouble()*10000;
double d2 = random.nextDouble()*10000;
double d3 = random.nextDouble()*10000;
trans = hello.setClass(a, d1, d2, d3);
System.out.println("a : " + trans.a);
System.out.println("arr0 : " + trans.arr[0]);
System.out.println("arr1 : " + trans.arr[1]);
System.out.println("arr2 : " + trans.arr[2]);
hello.sendClass(trans); //send to the server
}
} catch (Ice.LocalException e) {
e.printStackTrace();
status = 1;
} catch (Exception e) {
System.out.println(e.getMessage());
status = 1;
}
if(ic != null) {
try {
ic.destroy();
} catch (Exception e) {
System.out.println(e.getMessage());
status = 1;
}
}
System.exit(status);
} //main
} // Client
The server :
Code:
#include <HelloI.h>
#include <Ice/Ice.h>
using namespace std;
int
main(int argc, char* argv[])
{
int status = EXIT_SUCCESS;
Ice::CommunicatorPtr communicator;
cout << "Server ready ..." << endl;
try
{
communicator = Ice::initialize(argc, argv);
Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("Hello", "tcp -p 10000");
adapter->add(new HelloI, Ice::stringToIdentity("hello"));
adapter->activate();
communicator->waitForShutdown();
}
catch(const Ice::Exception& ex)
{
cerr << ex << endl;
status = EXIT_FAILURE;
}
if(communicator)
{
try
{
communicator->destroy();
}
catch(const Ice::Exception& ex)
{
cerr << ex << endl;
status = EXIT_FAILURE;
}
}
return status;
}
HelloI.cpp
Code:
#include <HelloI.h>
#include <Ice/Ice.h>
using namespace std;
void HelloI::sayHello(const string& s, const Ice::Current&)
{
cout << s << endl;
}
Demo::TransmitPtr HelloI::setClass(int a, double d1, double d2, double d3, const Ice::Current&) {
array arr (3);
arr[0] = d1;
arr[1] = d2;
arr[2] = d3;
TransmitPtr trans = new Transmit(a,arr);
cout << "in setClass..." << endl;
cout << "a : "<< trans->a << endl;
cout << "arr 0 : "<< trans->arr[0] << endl;
cout << "arr 1 : "<< trans->arr[1] << endl;
cout << "arr 2 : "<< trans->arr[2] << endl;
return trans;
}
void HelloI::sendClass(const TransmitPtr& trans, const Ice::Current&) {
array arr (3);
int a = trans->a;
for (int i = 0; i < 3; i++) arr[i] = trans->arr[i];
TransmitPtr trans_new = new Transmit(a,arr);
cout << "in sendClass..." << endl;
cout << "a : "<< trans_new->a << endl;
cout << "arr 0 : "<< trans_new->arr[0] << endl;
cout << "arr 1 : "<< trans_new->arr[1] << endl;
cout << "arr 2 : "<< trans_new->arr[2] << endl;
}
HelloI.h
Code:
#ifndef HELLO_I_H
#define HELLO_I_H
#include <Hello.h>
using namespace std;
using namespace Demo;
class HelloI : public Demo::Hello
{
public:
void sayHello(const string& s, const Ice::Current&);
Demo::TransmitPtr setClass(int a, double d1, double d2, double d3, const Ice::Current&);
void sendClass(const TransmitPtr& trans, const Ice::Current&);
};
#endif
Hello.ice
Code:
#ifndef HELLO_ICE
#define HELLO_ICE
module Demo
{
sequence<double> array;
class Transmit {
int a;
array arr;
}
interface Hello
{
void sayHello(string s);
Transmit setClass(int a, double d1, double d2, double d3);
void sendClass(Transmit trams);
};
};
#endif
Could you tell me how to get a stack trace ?
Thank you very much