简体   繁体   中英

Applet -> servlet -> another applet communication

I'm implementing a simple checkers game (java applets as clients + servlet) where two players can connect to the servlet and play. As I'm just beginning with applet-servlet programming, I have some problems with the proper communication.

Let's suppose the game begins and first player moves. Then I have to send his move to the servlet which should inform the other player. And here I don't know how to do that. How the servlet can pass received data to another applet, not the one that sent it? How and where should the servlet keep the info related to players so that it can recognize which one sent the data?

Fisrt: the servlet won't pass data or message to any servlet from its initiative. It will have to wait for the applet to send a request, and then will be able to send a proper response.

So, the simplest seems that your applets regularly send requests to the servlet, like "what's up?". It's the polling system ome is talking about. To recognize which player is polling, give them an id when they first access your servlet (register ?), and make that id present in every future request.

Is that clear enough ? :)

(and yes, next step is to use COMET)

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