Java: Sockets or RMI?

*爱你&永不变心* 提交于 2019-12-04 05:04:28

personally, RMI seems like a bit of overkill if you've just got one method to call, and all your data is already wrapped in a string. i imagine a simple socket server would suffice very well for your needs. however, RMI does give you a bunch of stuff for free, like multithreading, distributed garbage collection, object marshalling, etc etc. however if you only have 1 client then multithreading might not be useful and since you're doing your own object marshalling then these benefits might not gain you anything.

there's a good page on rmi's capabilities here : http://java.sun.com/javase/technologies/core/basic/rmi/whitepaper/index.jsp

since your protocol is already very simple (you just pass a string) I suggest that you just go with sockets. the advantage would be that you will not be tied up to Java on both ends, for example - it will be possible to switch the UI to another language easily.

Having done apps that used raw sockets to communicate, that used RMI, and that used SOAP, it's easiest (by a thin hair) to use RMI but then you're strongly bound to using Java for everything. The key to why RMI is easiest is that it ensures that whole messages are sent and includes a basic discovery framework, and yet it doesn't have the complexity of SOAP (which is a lot more complicated than everything else listed above).

You may consider wrapping your server entry point as a servlet and doing a POST from a client.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!