Archived

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

Multi-client, multi-server configuration

Hi,

I've to create a system where a client must send data to his related server.
Due to this, I'ill have many servers and clients.

The system should be like attached image. Attachment not found.

Server1 open a connection in port 10000, and Client1 sends and image in port 10000.

Server2 open in port 20000 and Client2 sends in port 20000 ...

Is there another way to implement this than creating threads for each connection? How?

Thanks !

Comments

  • Hello?

    Up
  • bernard
    bernard Jupiter, FL
    Hi Carlos,

    Your question is not clear. Threads and connections are not tied with Ice: for example, a single thread in a client could open multiple connections (invoke on multiple servers), and multiple threads in a client can all share the same connection (invoke on objects in the same server / object adapter).

    Naturally, if you have 3 clients, and each of these clients is calling objects in 3 servers, Ice will open at least 3 * 3 = 9 connections.

    Cheers,
    Bernard
  • 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:
    __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:
    __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;
    	}