Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet-servlet communication

 
Nasir Mkhan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tero Ahonen
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Hemant Bhaiya
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want to know Applet-Applet communication or Applet-servlet communication?
Please clarify.
Luv,
Hemant
 
Mohamed Yousuff
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.


------------------
 
Raghvendra Sharma
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Nasir Mkhan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all.
I have got the point to check.
Thanks once again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic