0

First of all I would like to thank all of the great people answering all kinds of questions on this awesome coding-website.

Now to my question:

I just started working with Google App Engine, because I want to use it for a java desktop application I made. The swing application is sending serialized objects from one client to another using sockets. This solution is pretty sloppy and it causes latency problems in some cases. I searched the web for possible server solutions and ended up with Google App Engine.

So, my question is basically: How do I send serialized objects from my swing application to the app engine application server, and vice versa? I have absolutely no idea if it is possible, although I read it can be done by faking the server into thinking I'm a user of the web application, and sending those objects via javascript to the server. Now, I don't know much about javascript, and would like to keep it on the java site, if possible.

I would appreciate any kind of code examples or ideas.

4

2 回答 2

0

您不能使用 TCP 套接字进行广播。为此,您必须使用 UDP 套接字通信。

如果您真的想使用虚拟主机来维护您的服务器,您可以执行以下操作

1) 使用 Java Servlet 实现服务器。您可以在 Google 应用引擎上托管 Java servlet。

2)在客户端程序中,使用HTTP而不是TCP套接字与服务器通信。

3)您可以如下实现虚拟广播

3.1)在Java客户端程序中,一旦你的程序启动就启动一个单独的线程

3.2) 在该线程中,使用 HTTP 请求继续 ping Servlet 并读取响应。使用这个逻辑,你可以刺激广播。

3.3) 你可能需要编写独立的 Servlet 来处理这个广播。

这些链接会有所帮助

如何在 Java 中发送 HTTP 请求?

http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/

于 2012-07-19T22:46:28.147 回答
0

谷歌应用引擎有一个叫做远程 API 的工具: https ://developers.google.com/appengine/docs/java/tools/remoteapi

这应该涵盖您的服务器 API。至于序列化,你可以做很多事情:JSON、XML 等。我个人更喜欢 JSON,并使用Jackson。google-gson 是您可能想要使用的另一个库。

于 2012-07-21T05:32:08.563 回答