简体   繁体   中英

How do I send serialized java objects from a swing application to a google app engine application and vice versa?

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.

You can not do broadcast using TCP socket. For that you have to use UDP socket communication.

If you really want to use web hosting for maintaining your server, you can do following things

1) Implement server using Java Servlet. You can host Java servlet on Google app engine.

2) In the client program, use HTTP instead of TCP socket to communicate with server.

3) You can implement virtual broadcast as follows

3.1) In Java client program, start a seperate thread as soon as your program is started

3.2) In that thread, keep pinging Servlet using HTTP request and read response. Using this logic, you can stimulate broadcast.

3.3) you might need to write Separate Servlet to handle this broadcast.

These links will be helpful

How to send HTTP request in java?

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

Google App Engine has tool that may help called Remote API: https://developers.google.com/appengine/docs/java/tools/remoteapi

That should cover the server API for you. As for serialization, you can do many things: JSON, XML, etc. Personally I prefer JSON, and using Jackson . google-gson is another library you may want to use instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM