File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Communication between applet instances Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Communication between applet instances" Watch "Communication between applet instances" New topic
Author

Communication between applet instances

Alexis Michael
Greenhorn

Joined: Mar 29, 2009
Posts: 9
Hi,

I was wondering, is there way for to separate applet instances (created from the same page but on different computers) to communicate with each other? I want to create a live message system (not going through a database) where a player can send a message to another player currently playing the same game.

I thought of having the messages stored in a db and having the applet refresh every 2 seconds to retrieve any newly stored messages but this seems too bandwidth-consuming. Am I wrong?

Thank you
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41818
    
  62
not going through a database

I thought of having the messages stored in a db

OK, so I see some conflicting requirements here :-)

You'll need some active server-side component, like a servlet. That would send and receive messages from/to each user, and store them (possibly in memory) in between. Wouldn't have to be a servlet, though - any language would be fine, although I'd probably go for HTTP as the protocol. And it would need to run on the same server where the applets are served from, or you'll need to work around security restrictions.

I don't necessarily see a bandwidth problem caused by checking every 2 seconds (assuming we're not talking about hundreds of clients) - request and response would be quite short unless there was actual data to be transported. It may not make sense because of the network latency, though, or because people simply don't send messages that often and that quickly.


Ping & DNS - my free Android networking tools app
Alexis Michael
Greenhorn

Joined: Mar 29, 2009
Posts: 9
yeah my initial thought was going through a db, and i was looking for something not going through a db.

given that i am not really familiar with servlets and short on time, do you think that storing the messages in a db and performing queries every 1-2 secs is a good idea? the game will not be playing by hundreds i assure you ;p it is for a uni project.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41818
    
  62
For a school project it's fine, but in general, using JDBC in applets is not a good idea for security reasons. And most decidedly so if the applet is accessible from outside of the firewall.

The DB needs to be on the same machine as the web server, or you'll run into the applet sandbox restrictions.
Alexis Michael
Greenhorn

Joined: Mar 29, 2009
Posts: 9
im not connecting directly via jdbc, im using PHP as an intermediate tier
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Communication between applet instances