简体   繁体   English

将数据从服务器发送到特定客户端

[英]Send data from server to a specific client

I have a little problem in my multi-client/server application. 我的多客户端/服务器应用程序中有一个小问题。 I need to send specific data to a single client from the server but I don't know how to do it. 我需要将特定数据从服务器发送到单个客户端,但是我不知道该怎么做。 I temporarily solved this problem by adding an header with the client specification. 我通过在客户端规范中添加标头来临时解决了此问题。 But it isn't the best solution because the server every time send the data to all the client connected. 但这不是最佳解决方案,因为服务器每次都会将数据发送到所有连接的客户端。 How can I solve this problem? 我怎么解决这个问题?

I had a similar problem. 我有一个类似的问题。 I added a field to the web service containing a guid. 我在Web服务中添加了一个包含GUID的字段。 Obviously all the clients pole the service at regular intervals to ascertain they need new data. 显然,所有客户都定期提供服务,以确保他们需要新数据。 If a client needs to be sent extra data, when it makes a regular request to the server the server reads it's client id and creates the appropriate guid which it returns in it's regular data feed. 如果需要向客户端发送额外的数据,则当它向服务器发出常规请求时,服务器会读取其客户端ID并创建适当的GUID,并在其常规数据Feed中返回该GUID。 When the client reads the guid field as not null, it calls the second web method, using the guid as an argument. 当客户端读取的guid字段不为null时,它将使用guid作为参数来调用第二个Web方法。 The second web method reads the guid and uses it to look up then return the extra required data. 第二种Web方法读取guid并使用它进行查找,然后返回额外的必需数据。 An alternative would be to use push technology by keeping the connection open and keeping the client in permanent state of 'loading'. 一种替代方法是使用推技术,方法是保持连接打开并保持客户端处于“加载”的永久状态。 When there is additional client specific data, the server can inject some code, eg javascript, into the permanently open request which will then request the new data from the server. 当有其他特定于客户端的数据时,服务器可以将一些代码(例如javascript)注入到永久打开的请求中,该请求随后将向服务器请求新数据。 Based on my experiences of implementing push technology would leads me to advising you try the former method above. 根据我实施推送技术的经验,我会建议您尝试上面的前一种方法。 The only other option would be to install some kind of server application on your client to receive pushed data. 唯一的其他选择是在客户端上安装某种服务器应用程序以接收推送的数据。

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

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