简体   繁体   English

Web应用程序的两个客户端之间的通信

[英]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 客户端1-将客户端2的消息发送到服务器
  2. Client2 - check any period of time for the messages Client2-检查消息的任何时间段

OR 要么

  1. Client2 - Open Websocket to the server. Client2-打开Websocket到服务器。
  2. Client1 - send message for client2 to server 客户端1-将客户端2的消息发送到服务器
  3. Server - push message to client2 服务器-将消息推送到client2

direct client-to-client communication my be very difficult due to client firewalls. 由于客户端防火墙的原因,直接进行客户端到客户端的通信非常困难。

Look at the tutorial for sockets in java 查看教程中的Java套接字

http://docs.oracle.com/javase/tutorial/networking/sockets/ 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 Client1将其传出发送到Client2的传入

Client2 hears on its incoming and responds on its outgoing to Client1's incoming Client2听到其传入消息,并响应其传出到Client1的传入消息

Client1 hears on its incoming Client1听到传入消息

You can use the standard Java JMS approach to send asynchronous messages between applications. 您可以使用标准的Java JMS方法在应用程序之间发送异步消息。 Read more at : http://java.sun.com/developer/technicalArticles/Ecommerce/jms/ 有关更多信息,请访问: 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. 如果通过Web应用程序表示基于HTTP,则必须知道HTTP是基于请求的协议。 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. 换句话说,服务器仅响应来自客户端(大多数情况下为浏览器)的HTTP请求,因此,在客户端发送消息后,所有想要接收该消息的其他客户端都必须请求它,即make对服务器的请求。 Typically, this is achieved using an auto-refreshed HTML page. 通常,这是使用自动刷新的HTML页面来实现的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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