1

I'm building a chat application that allows people from any website to communicate with my website. Here's the visual breakdown:

Website A    Server        Website B
   Msg1 -------> Msg1 -------> Msg1
                                                |
   Msg2 <------- Msg2 <------- Msg2

Right now I'm using a polling solution that works for the time being, but it won't scale.

I'm wondering what solid solutions there are that I could use to facilitate this messaging functionality. I looked at JMS briefly, but it looked like it was only for communication from one Java server to another (not HTML to Java to HTML which is what my setup requires)

Trevor
  • 1,137
  • 1
  • 19
  • 33
  • If the current solution do not like, I can only think in WebSockets, but you are looking for scalability, see [Server Scalability - HTML 5 websockets vs Comet](http://stackoverflow.com/questions/9107384/server-scalability-html-5-websockets-vs-comet). – Paul Vargas Oct 02 '13 at 14:40

2 Answers2

1

The most easy way would be to set up a database on the server (SQL/ MySQL) and then let the websites communicate with this server. (so this kind of leaves the Java server out of the question)

This is a nice stack question about that.

How you could build it is for example:

- server passes chat-id to both clients after identification
- clients recognise id and store id
- clients keep calling for the database through AJAX calls
  - depending on how the database is designed, it could then update the client's chat 
    screens whenever a new row has been added to the specified database table.

Be careful for SQL-injection though. You don't want people to be able to read all conversations.

Apart from building your own solution, I can highly recommend going with one of the existing plugins.

For example this list of 10 free Website Chat Widgets is pretty good, but there is most definitely already something (open source) out there that fits your needs.

For example this plugin and this plugin looks nice if you want server side regulation. (Haven't used it myself though)

Or if you just want the 'framework' (as far as I may call it a framework), you can use the very low-end solutions like Blueimp's AJAX Chat.

Good luck!

Community
  • 1
  • 1
Jean-Paul
  • 19,910
  • 9
  • 62
  • 88
  • I already have a database set up, and that's why it's not an efficient solution, as it's constantly polling. I want a solution that will be able to communicate from the Java server to the HTML pages when a message needs to be delivered (as opposed to the current solution where the HTML pages poll the Java server/SQL database to see if there are messages needing to be delivered) – Trevor Oct 02 '13 at 15:32
  • @Trevor: Then you would need to set up a [server push system](http://en.wikipedia.org/wiki/Push_technology). Please read this question: http://stackoverflow.com/questions/7698739/server-side-push-with-java – Jean-Paul Oct 02 '13 at 16:42
1

I wrote blog about how to implement Java WebSocket on Glassfish 3.1.2.2 but It's is Thai language. .... But I thought you can guess from code.

Anyway If you have any problem. You can ask me.

Peerapat A
  • 420
  • 4
  • 13