Hello all of you. I am developing online chess game in which two players can play with each other using chess applet through servlet.How can i send the parameters received from one applet to another and vice versa in order to repaint the applet to show the action of other? Can anyone plz tell me. Thanks in any case.
Joined: May 24, 2001
Use javaranch's own com.javaranch.common package (http://www.javaranch.com/common.jsp). There is couple of classes (ObjectServlet, HTTP, etc.) which can be used for applet-servlet-applet communication. -Tero
Joined: Nov 01, 2000
You want to know Applet-Applet communication or Applet-servlet communication? Please clarify. Luv, Hemant
Joined: Jun 23, 2001
There is a way to solve this problem. You have to develop a servlet which will store the action of the players in a session. The applet which comes to the front end in the client browser window will run a thread which will contact the servlet and retrieve the latest changes from the opposite side. This should be done in a separate thread and should be repeated every few seconds. There are some ways for the applet to contact the servlet. It can use the HttpUrlConnection in the java.net package or use rmi or use socket. You need to consider these techniques based on your requirements. Note that this problem is not new. This is typical of an online chat application using applets.
Originally posted by Abdul Nasir: Hello all of you. I am developing online chess game in which two players can play with each other using chess applet through servlet.How can i send the parameters received from one applet to another and vice versa in order to repaint the applet to show the action of other? Can anyone plz tell me. Thanks in any case.
Joined: Oct 09, 2000
Hi, I have developed an applet, that fetches data from the servlet (really a huge chunk) and then posts at regular intervals. Its actually a test applet. I have used the serialization funda for passing data between applet and servlet. It has worked good for me without problems. You can also try it 1. open a urlconnection to the servlet 2. get the output stream of the connection, with output enabled 3. create an object output stream with url con.'s o/p stream as parameter 4. write to objectoutput stream your object. (your obj. must be serializable ) similarly read from the urlcon.'s input stream.
Hope it helps. thanks n regards raghav.. [This message has been edited by Raghvendra Sharma (edited June 26, 2001).]
Joined: May 13, 2001
Thanks to all. I have got the point to check. Thanks once again.