C#套接字与管道

前端之家收集整理的这篇文章主要介绍了C#套接字与管道前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
目前,我正在 Windows上使用多进程桌面应用程序.这个应用程序将是一个收缩包装的应用程序,将被部署在世界各地的客户端机器上.虽然我们可以为机器提供广泛的规格 – 例如Windows XP SP3与.Net 4.0 CF,我们不能控制它们,我们不能太具体的配置 – 例如我们不能指定机器必须有一个cuda 1.4能力的图形处理器等

其中一些进程被管理(.Net 4.0),其他进程被管理(C Win32).这些进程需要共享数据.迄今为止我评估的选项是

> Tcp套接
>命名管道

管道看起来好一点,但是对于我们的需求 – 两者的性能都是可以接受的.并且套接字给我们跨越机器(和操作系统 – 我们希望最终支持非Microsoft OSes)的灵活性在未来的边界,因此我们喜欢​​使用套接字.

然而,我的主要关注点是 – 如果我们使用Tcp套接字 – 我们是否有可能遇到防火墙的问题?有没有人部署桌面应用程序/程序使用TCP IPC和经验的问题?如果是这样 – 什么样的?

我知道这是一个相当公开的问题,我很乐意改写.但我真的很想知道我们有可能遇到什么样的潜在问题.

编辑:要多一点点光 – 我们只传输几个POD,int,float和string.我们已经建立了一个抽象层,提供了2个范例 – 请求/响应和订阅.传输层已被抽象出来,目前我们有两个实现 – 基于管道和基于TCP.

解决方法

快速LAN上管道的性能通常更好,但TCP在较慢的网络或WAN上往往更好.请参见下面的msdn点.

TPC更可配置.关于防火墙,它们允许您打开/关闭通信端口.如果这不是一个选择或担心,另一个选项将是http(REST / json,web service,xml rpc等),但不知道http开销是否可以接受.确保使用真实世界的数据集(在测试中传递微不足道的数据)使开销似乎不合理 – 通常,与现实世界数据集相比是一个较小的数据集).

msdn的其他信息:

In a fast local area network (LAN) environment,Transmission Control
Protocol/Internet Protocol (TCP/IP) Sockets and Named Pipes clients
are comparable in terms of performance. However,the performance
difference between the TCP/IP Sockets and Named Pipes clients becomes
apparent with slower networks,such as across wide area networks
(WANs) or dial-up networks. This is because of the different ways the
interprocess communication (IPC) mechanisms communicate between peers.

For named pipes,network communications are typically more
interactive. A peer does not send data until another peer asks for it
using a read command. A network read typically involves a series of
peek named pipes messages before it begins to read the data. These can
be very costly in a slow network and cause excessive network traffic,
which in turn affects other network clients.

It is also important to clarify if you are talking about local pipes
or network pipes. If the server application is running locally on the
computer running an instance of Microsoft® sql Server™ 2000,the local
Named Pipes protocol is an option. Local named pipes runs in kernel
mode and is extremely fast.

For TCP/IP Sockets,data transmissions are more streamlined and have
less overhead. Data transmissions can also take advantage of TCP/IP
Sockets performance enhancement mechanisms such as windowing,delayed
acknowledgements,and so on,which can be very beneficial in a slow
network. Depending on the type of applications,such performance
differences can be significant.

TCP/IP Sockets also support a backlog queue,which can provide a
limited smoothing effect compared to named pipes that may lead to pipe
busy errors when you are attempting to connect to sql Server.

> In general,sockets are preferred in a slow LAN,WAN,or dial-up
network,whereas named pipes can be a better choice when network speed
is not the issue,as it offers more functionality,ease of use,and
configuration options.

For more information about TCP/IP,see the Microsoft Windows NT® documentation.

原文链接:https://www.f2er.com/csharp/96290.html

猜你在找的C#相关文章