MrProper
MrProper

Reputation: 1580

Communication between two clients of web application

Let's say I want to send a message from one client to another. How should I approach this problem? Obviously I will have to send this message to server, but what's next? I have few ideas, but every idea seems to be wrong.

thanks

Upvotes: 0

Views: 1160

Answers (4)

Matei Florescu
Matei Florescu

Reputation: 1195

If by web application you mean HTTP based, than you must know HTTP is a request based protocol. In other words, the server only responds to HTTP requests that come from the clients (browsers, most of the time), so after a client sends a message, all the other clients that want to receive that message must ask for it, i.e. make a request to the server. Typically, this is achieved using an auto-refreshed HTML page.

Upvotes: 0

Ahmed Hashem
Ahmed Hashem

Reputation: 360

You can use the standard Java JMS approach to send asynchronous messages between applications. Read more at : http://java.sun.com/developer/technicalArticles/Ecommerce/jms/

Upvotes: 0

Roman K
Roman K

Reputation: 3337

  1. Client1 - send message for client2 to server
  2. Client2 - check any period of time for the messages

OR

  1. Client2 - Open Websocket to the server.
  2. Client1 - send message for client2 to server
  3. Server - push message to client2

direct client-to-client communication my be very difficult due to client firewalls.

Upvotes: 3

twain249
twain249

Reputation: 5706

Look at the tutorial for sockets in java

http://docs.oracle.com/javase/tutorial/networking/sockets/

Also you don't necessarily need a server. You can have the clients have both an incoming and outgoing channel and do it that way.

So

Client1 sends on its outgoing to Client2's incoming

Client2 hears on its incoming and responds on its outgoing to Client1's incoming

Client1 hears on its incoming

Upvotes: 0

Related Questions