如何最轻松地在同一主机上运行的 Cocoa(客户端)和 Java(服务器)之间进行 IPC/RPC?
Java 端是一个 Bukkit 插件,所以我没有自由在 Tomcat 这样的 servlet 引擎上构建。我不需要任意访问任何对象;我只想将插件可用的功能子集公开到我的包装应用程序。
Cocoa 应用程序是我从头开始构建的,因此限制稍微宽松一些。它是服务器的包装器,对配置某些插件的支持有限。
可以通过 Unix 套接字进行通信的东西将是理想的,因为进程在单个主机上运行,但 TCP 套接字也可以。我其实并不挑剔。如果我最终使用 TCP,那么我会考虑添加对远程管理的支持,但这不是优先事项。我不想太需要 Unix 套接字来打扰我的所有麻烦。必须跳过才能使用它们。
The Java end is a Bukkit plugin, so I don't have the freedom to build on a servlet engine like Tomcat. I don't need arbitrary access to any object; I just want to expose a subset of functionality available to plugins to my wrapper application.
The Cocoa application, I am building from the ground up, so the restrictions are a bit looser. It's a wrapper for the server with limited support for configuring certain plugins.
Something that can communicate over Unix sockets would be ideal since the processes are running on a single host, but TCP sockets are ok too. I'm not really picky. If I end up using TCP then I'll consider adding support for remote management, but it's not a priority. I don't want Unix sockets badly enough to bother with all the hoops I'd have to jump through to use them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能想看看 zeromq,它具有 Objective-C 和 Java 的绑定,支持 IPC、TCP 和更多的。
You might want to look at zeromq, it has bindings for Objective-C and Java, supports IPC, TCP, and more.
Java 不支持开箱即用的 UNIX 套接字,但是这个问题给出了一些替代方案。
或者您可以在本地主机上打开一个 tcp 套接字以保留在标准库中。
有很多解决方案,但如果您想保持精简和精简,一个简单的插座也不错。所有盒装解决方案都非常复杂,因为它们需要通过网络处理复杂的问题。您将只面对其中的一小部分,因此通过套接字使用简单的自制协议可能会更好。
只需使其异步以避免阻塞。
Java does not support UNIX sockets out-of-the box, but this question gives some alternatives.
Or you can just open a tcp socket on localhost to keep in the standard library.
There are a lot of solutions out there, but if you want to stay lean and mean, a simple socket is not too bad. All the boxed solutions are quite complex, as they need to deal with complex issues over the net. You will face only a small subset of these, so might be better of with a simple home-grown protocol over a socket.
Just make it asynchronous to avoid blocking.