2

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?

4

2 回答 2

0

我发现解决这个问题最有效的方法是显式传递对调用对象的引用,例如方法的第一个参数。这样,调用对象可以很容易地被识别,甚至在必要时回调。结果参数的类型为NSDistantObject *

于 2012-02-29T08:06:05.320 回答
0

我有一个类似的问题。我发现识别客户端的一种可能方法是让它们将某种令牌对象作为每次调用的一部分传递给服务器。在服务器上,您可以执行以下操作:

NSConnection* clientConnection = [passedTokenObject connectionForProxy];

这将使您掌握连接的句柄,这对于每个客户端都是唯一的。您能否获得所需的信息取决于 Apple 允许您使用该连接对象做什么。

在我的应用程序中,我让客户首先进行“注册”调用,我用它来收集我需要的关于他们的信息。

另一件可能有用的事情是成为用于出售服务器对象的 NSConnection 的 NSConnectionDelegate。这将使您可以访问这些方法:

- (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;
}

我发现可用的“工具”还不够,我需要重新设计我出售的 API 以帮助提供我需要的信息。

于 2012-01-07T18:09:09.487 回答