如何找到特定分布式对象方法调用的连接?
我有一个 Cocoa 客户端和服务器应用程序,它们使用通过 NSSocketPorts 和 NSConnections 以标准方式实现的分布式对象进行通信。服务器向客户端应用程序提供单个对象,其中可能有多个。每个客户端应用程序都可以通过其自己的代理来访问同一分布式对象。
出售的对象支持特定的协议,其中包括类似于以下的方法:
@protocol VendedObjectProtocol
- (void) acquireServerResource:(ServerResourceID)rsc;
@end
当客户端应用程序调用此方法时,服务器应该将请求的资源分配给该客户端应用程序。但是可能有多个客户端请求相同的资源,服务器需要跟踪哪些客户端请求了它。
我希望能够在服务器端执行的操作是确定客户端方法调用所使用的 NSConnection。我怎样才能做到这一点?
我想到的一种方法是(服务器端):
- (void) acquireServerResource:(ServerResourceID)rsc withDummyObject:(id)dummy {
NSConnection* conn = [dummy connectionForProxy];
// Map the connection to a particular client
// ...
}
但是,我真的不希望客户端出于没有真正目的的情况而必须传递虚拟对象(从客户端的角度来看)。我可以将 ServerResourceID 设为一个类,以便它作为代理传递,但我也不想真正这样做。
在我看来,如果我使用原始套接字进行通信,我将能够找出消息来自哪个套接字,因此能够确定哪个客户端发送了它,而客户端不需要发送任何特殊的内容的消息。我需要一种通过分布式对象方法调用来做到这一点的方法。
谁能建议一种机制来做到这一点?
I have a Cocoa client and server application that communicate using distributed objects implemented via NSSocketPorts and NSConnections in the standard way. The server vends a single object to the client applications, of which there may be several. Each client application can gain access to the same distributed object getting its own proxy.
The vended object supports a particular protocol, which includes a method similar to the following:
@protocol VendedObjectProtocol
- (void) acquireServerResource:(ServerResourceID)rsc;
@end
When a client application invokes this method, the server is supposed to allocate the requested resource to that client application. But there could be several clients that request the same resource, and the server needs to track which clients have requested it.
What I'd like to be able to do on the server-side is determine the NSConnection used by the client's method invocation. How can I do that?
One way I have thought about is this (server-side):
- (void) acquireServerResource:(ServerResourceID)rsc withDummyObject:(id)dummy {
NSConnection* conn = [dummy connectionForProxy];
// Map the connection to a particular client
// ...
}
However, I don't really want the client to have to pass through a dummy object for no real purpose (from the client's perspective). I could make the ServerResourceID be a class so that it gets passed through as a proxy, but I don't want to really do that either.
It seems to me that if I were doing the communications with raw sockets, I would be able to figure out which socket the message came in on and therefore be able to work out which client sent it without the client needing to send anything special as part of the message. I am needing a way to do this with a distributed objects method invocation.
Can anyone suggest a mechanism for doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在寻找的是 NSConnection 的 委托方法。例如:
您可以为每个单独的连接设计一个对象(如 VendObjectProtocol)并通过 self.connection 获取连接。
或者
您可以使用对话令牌 +createConversationForConnection:和 +当前对话
What you are looking for are NSConnection's delegate methods. For example:
You could design an object for each individual connection (like VendedObjectProtocol) and get the connection with self.connection.
Or
You can make use of conversation tokens using +createConversationForConnection: and +currentConversation