• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Communication between applet instances

 
Alexis Michael
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alexis Michael
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im not connecting directly via jdbc, im using PHP as an intermediate tier
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic