简体   繁体   中英

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

  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.

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

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/

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, ie make a request to the server. Typically, this is achieved using an auto-refreshed HTML page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM