Archived

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

Proxy from Servants and vicecersa.

My program is going to play mp3 in the only machine that have speakers in my lan (i'll call it server). I'm going to use this interface to transfer a buffer of a mp3file from my clients:

module Q4MusicClient
{
sequence<byte> ByteSeq;

interface Mp3Client
{
nonmutating ByteSeq GetBuffer(int pos, int size);
}
}

Every clients know what to transfer, so in my "sever" application i call that method on every client until the buffer size is zero, and then i move to the next client.

The only two server methods for now are:

module Q4MusicServer
{
interface Mp3Server
{
// Add a client to ask for mp3
idempotent void RegisterClient(Q4MusicClient::Mp3Client* c);

// Remove the client from the queue
idempotent void UnregisterClient(Q4MusicClient::Mp3Client* c);
};
};

I set up my server all right. I also setup my client this way:

adapter= communicator->createObjectAdapter("Mp3Client");

// Instantiate the servant.

Ice::ObjectPtr servant= new Q4MusicClient::Mp3ClientI;
adapter->add(servant, Ice::stringToIdentity("mp3Client"));
adapter->activate();

Q4MusicClient::Mp3ClientPrx ClientProxy= SomeWayToGetTheProxyFromTheServant(servant); ???

The last line is suposed to get a proxy to the servant i have just created, but i con't know how to obtain the proxy from the actual real object "servant".

I need a proxy even being on the client because when i register to the server with the server interface "idempotent void RegisterClient(Q4MusicClient::Mp3Client* c);" i want to pass a proxy to myself so the server can communicate to the client using that proxy.

How do i do that?

Thanks!

Comments

  • mes
    mes California
    Hi,

    As explained in section 30.4.4 of the manual, the return value of ObjectAdapter::add is a proxy for the servant that you can downcast to the appropriate type:
    Q4MusicClient::Mp3ClientPrx proxy = 
        Q4MusicClient::Mp3ClientPrx::uncheckedCast(adapter->add(...));
    
    Hope that helps,
    - Mark