Ok, then I could have 3 clients calling the same function at the same server. But how can I do this sendind information in different ports?
Example:
1 server.
3 clients. Client1, Client2, Client3. Each client sends grab pictures from a different directory and sends to the server.
Client1 must send by port 10000, client2 by port 11000 and client3 by port 12000.
How can i do this?
my actual code is:
Client code:
Code:
__declspec(dllexport) int run(){
Sleep(1000);
//std::string s(std::string(puerto) +":default -p "+std::string(puerto));
std::string s(std::string(puerto) +":default -p 10000");
Ice::CommunicatorPtr communicator; //Por ello tenemos que crear el Communicator
communicator = Ice::initialize();
Ice::ObjectPrx base = communicator->stringToProxy(s);
Proyecto::ImageProviderPrx imagenPrx = ImageProviderPrx::checkedCast(base);
if (strcmp(tipo,"JPG")==0){
coleccionImagenes(imagenPrx);
}
else if (strcmp(tipo, "AVI")==0){
archivoVideo(imagenPrx);
}
//communicator->waitForShutdown();
communicator->destroy();
/*if (communicator){
communicator->destroy();
}*/
return 0;
}
Functions coleccionImagenes and archivoVideo calls sendImageData, which sends to server.
run is executed in 3 threads, one per client(variable puerto changes in each call)
Server code:
Code:
__declspec(dllexport) int run(){
Ice::CommunicatorPtr ic;
ic = Ice::initialize();
char* port=puerto;
//std::string s("default -p "+ std::string(port));
std::string s("default -p 10000");
Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWithEndpoints(port, s);
Ice::ObjectPtr object = new ImagenI(port);
cout << "Identidad adaptador ";
cout << adapter->getName().data() << endl;
adapter->add(object, ic->stringToIdentity("10000")); //si ponemos "Imagen" tenemos el mismo identificador para todos
adapter->add(object, ic->stringToIdentity("11000"));
adapter->activate();
ic->waitForShutdown();
ic->destroy();
if (ic) {
try {
ic->destroy();
} catch (const Ice::Exception& e) {
cerr << "cerrando";
}
}
return 0;
}