简体   繁体   English

节俭:向连接到服务器的所有客户端发送消息

[英]Thrift: Send a message to all clients connected to the server

I written a client server program using the Thrift framework, since the server is coded in C# and the clients are in Java.My question is, how can I make a message listener using Thrift? 我用Thrift框架编写了一个客户端服务器程序,因为服务器是用C#编码的,而客户端是用Java编写的。我的问题是,如何使用Thrift制作消息监听器? For example, my program has a list that the server sends to each client when one connects to it. 例如,我的程序有一个列表,当一个服务器连接到每个客户端时,服务器就会发送给每个客户端。 If I have three clients connected to the server, and one of them modifies that list (which is declared before the server starts), how can I notify the rest of the clients that the list was modified? 如果我有三个客户端连接到服务器,并且其中一个客户端修改了该列表(在服务器启动之前声明),那么如何通知其余客户端列表已被修改?

Thank you. 谢谢。

Since you server is in C#, you can try use SignalR: https://www.codeproject.com/Articles/633378/ASP-NET-SignalR-Basis-Step-by-Step-Part 由于服务器位于C#中,因此您可以尝试使用SignalR: https ://www.codeproject.com/Articles/633378/ASP-NET-SignalR-Basis-Step-by-Step-Part

Other more dificult way is the direct use of Sockets: https://msdn.microsoft.com/en-us/library/w89fhyex(v=vs.110).aspx 其他更困难的方法是直接使用套接字: https : //msdn.microsoft.com/zh-cn/library/w89fhyex(v= vs.110).aspx

The question has been asked a number of times in various ways. 已经以各种方式多次询问了该问题。 There is also at least one yet unsolved JIRA ticket around. 周围至少还有一张尚未解决的JIRA票证

The general answer is at this time, given the current status quo: No built-in way, but there are indeed some viable alternatives: 鉴于目前的现状,目前的一般答案是:没有内置方法,但确实有一些可行的替代方法:

Option #1: One can use long polling or similar mechanisms to simulate it. 选项#1:可以使用长时间轮询或类似机制进行模拟。 This comes especially handy when clients live in a browser. 当客户端位于浏览器中时,这特别方便。

Option #2: If the clients are not living in a browser, the recommended way is to have the client start its own Thrift server, allowing the server to create a connection back to the client. 选项2:如果客户端不在浏览器中,建议的方法是让客户端启动其自己的Thrift服务器,从而允许该服务器创建与客户端的连接。

Option #3: Regarding @Rui's comment: Thrift is both a serialization and RPC framework. 选项#3:关于@Rui的评论:Thrift是序列化和RPC框架。 This offers the option to only use the serialization part of it and transport the messages in different ways, even outside of Thrift RPC. 这提供了仅使用序列化部分并以不同方式传输消息的选项,即使在Thrift RPC之外也是如此。 We did that with message bus systems and it works great. 我们使用消息总线系统做到了这一点,并且效果很好。

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

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