开发者

java: merging a server into the client

i have a very simple turn-based online game in java. the client talks to the server using normal java sockets.

now in order to play the game offline as well, i want to merge the server into the client.

what is not possible is to just launch the server as running on localhost and the client connecting to that. i simple cant use any network-stuff anymore. so i would like to auto-convert the protocol to some input/outputstream thing.

any ideas on how i could go ab开发者_StackOverflowout that? what technologies to use?

thanks!


You should be able to to run the server at the same time, but I think the cleaner solution is to abstract the remote server calls into an interface or set of interfaces. You can place your existing code in one implementation, and your localhost 'server' in another. Its just a matter of binding the appropriate version.

The localhost version can just be a direct call into the server, maybe faking the oneway call with an executor service. There should be some performance benefit as you won't need to spend extra time serializing and deserializing your messages. The abstracted facade is nice because you can place cooked implementations for testing.

As for running the server within the same process as the client there shouldn't be a restriction on this, other than the server is started first ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜