Question

I am using Distributed Objects (DO) in Objective-C. I have a "server" object that I have vended on the network. Other objects on the network have a proxy to my server object and can thus call methods on the server object. However, can I determine any information about the objects that are calling methods on the server object? That is, I have many "client" objects that can call the server and I would like to distinguish these objects. Also, can I determine other attributes about these objects, e.g., host name, unique identifier?

Was it helpful?

Solution 2

I found that the most effective solution to this problem is to explicitly pass a reference to the calling object as, say, the first parameter of the method. That way, the calling object can be easily identified and even called back if necessary. The resulting argument is of type NSDistantObject *.

OTHER TIPS

I had a similar problem. I found that a possible way to identify clients is to have them pass some kind of token object through to the server as part of each call. On the server you can do:

NSConnection* clientConnection = [passedTokenObject connectionForProxy];

This will get you a handle on the connection, which will be unique to each client. Whether or not you can get the information you need depends on what Apple allows you to do with that connection object.

In my application, I had clients first do a "registration" call that I used to gather the information I needed about them.

The other thing that might be useful is to become NSConnectionDelegate for the NSConnection that you use to vend your server object. This will give you access to these methods:

- (BOOL)connection:(NSConnection *)parentConnection shouldMakeNewConnection:(NSConnection *)newConnnection {
    //  You can inspect new connection being established here and maybe glean info about the client
    return YES;
}

- (BOOL) connection:(NSConnection *)c handleRequest:(NSDistantObjectRequest*)doReq {
    //  You get to see every method that is invoked here and can maybe glean info that you need.
    //  Returning NO means you're just snooping on the call and it will be handled in the normal way.
    return NO;
}

The available "tools" aren't very sufficient I have found and I needed to rework my vended API to help provide the information I needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top