两种方式通信服务器/客户端架构? [英] Two way communicating server/client architecture?

查看:28
本文介绍了两种方式通信服务器/客户端架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚我们的新应用程序要使用哪种客户端/服务器技术(即 .NET Framework 的哪一部分).我们将使用 .NET 3.5 SP1 用 C# 编写应用程序.

I'm trying to figure out which client/server technology (i.e. which part of the .NET Framework) to use for our new application. We will be writing the app in C# using .NET 3.5 SP1.

它将包含一个作为服务器"运行的中央服务,以及分布在多台机器上的几个客户端应用程序.客户端应用程序是一个托盘应用程序,它将接收来自服务器的通知,并将一些信息发送回服务器.因此,通信将是双向的,并且需要快速.服务器需要知道将通知发送到哪个客户端.

It is going to consist of a central Service that will be running as a "server", and several client applications spread out on several machines. The client application is a trayapp application that is going to receive notifications from the server, and will also send some information back to the server. The communication will therefore be two-way, and it needs to be fast. The server will need to know which client to send the notifications to.

我一直在想我可以使用套接字.我还遇到了 TcpListener 和 TcpClient 类.另一种选择是使用 WCF 做一些事情,但我不确定如何与它进行快速双向通信.

I've been thinking that I could use Sockets. I've also come across the TcpListener and TcpClient classes. Another alternative is to do something with WCF, but I'm not sure how to do fast two-way communication with it.

推荐答案

在不知道您计划交换多少数据的情况下,很难做出准确的建议.我使用 WCF 和 TCP 套接字在我的 UI 和我的 Windows 服务之间交换数据.以下是我的考虑.

Without knowing how much data you're planning to exchange, it's difficult to make a precise recommendation. I use both WCF and TCP sockets to exchange data between my UI and my Windows service. Here are the considerations I made.

我将 WCF 用于我所说的非周期性数据交换.例如,当我的 Windows 服务中发生事件时,我使用 WCF 将该事件传达给 UI.特别是对于这种基于事件的机制,我强烈推荐 Juval Lowy 的 发布订阅框架,可在此处免费获得.我还使用 WCF 将配置更改从 UI 传达到 Windows 服务.WCF对我来说是这种数据交换的完美解决方案.

I use WCF for what I refer to as aperiodic data exchange. For example, when an event occurs in my Windows service, I communicate the event to the UI using WCF. Specifically for this event-based mechanism, I would highly recommend Juval Lowy's Publish-Subscribe Framework, which is available for free here. I also use WCF to communicate configuration changes from the UI to the Windows service. WCF is a perfect solution for this kind of data exchange for me.

当用户告诉我的 Windows 服务执行某些操作时,大量数据会从 Windows 服务发送到 UI.为此,我使用 TCP 套接字.我知道 WCF 具有流式处理功能,因此我强烈考虑使用它.在我不得不做出决定之前,我只是没有时间适应它,所以我按照我所知道的去做.

When the user tells my Windows service to perform some action, a lot of data is sent from the Windows service to the UI. For this, I use TCP sockets. I know WCF has a streaming capability, and I strongly considered using it. I just did not have time to get comfortable with it before I had to make a decision, so I went with what I knew.

虽然我希望我使用 WCF 来实现对称性,即非周期性和流数据,但这种混合方法对我很有用.

While I wish I was using WCF across the board for symmetry, i.e., for aperiodic and streaming data, this hybrid approach has served me well.

希望这会有所帮助.

这篇关于两种方式通信服务器/客户端架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆