开发者

Applet -> servlet -> another applet communication

开发者 https://www.devze.com 2023-04-11 20:39 出处:网络
I\'m implementing a simple checkers game (java applets as clients + servlet) where two players can connect to the servlet and play. 开发者_JS百科As I\'m just beginning with applet-servlet programming,

I'm implementing a simple checkers game (java applets as clients + servlet) where two players can connect to the servlet and play. 开发者_JS百科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)

0

精彩评论

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

关注公众号