Windows上本地IPC的套接字vs命名管道? [英] Sockets vs named pipes for local IPC on Windows?

查看:328
本文介绍了Windows上本地IPC的套接字vs命名管道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于本地IPC(都使用win-api),有效性-wiz,资源-wiz或其他方式,是否有任何理由偏爱命名管道而不是套接字,因为两者的行为非常相似(并且可能通过类似的接口进行抽象)无论如何),在可能已经将套接字用于网络目的的应用程序中?

Are there any reasons for favoring named pipes over sockets for local IPC (both using win-api), effectiveness-wize, resource-wize or otherwise, since both behave very much alike (and likely to be abstracted by a similiar interface anyway), in an application that is likely to already use sockets for network purposes anyway?

我至少可以解决这个问题:套接字的端口号与管道的文件名.同样,尽管被阻止的应用程序仍可以通过本地套接字进行通信,但命名管道(AFAIK)不会向防火墙发出警报(阻止/取消阻止对话框).还有什么要考虑的吗?

I can name at least the addressing issue: port numbers for sockets against filenames for pipes. Also, named pipes (AFAIK) won't alert the firewall (block/unblock dialog), although blocked applications can still communicate via sockets locally. Anything else to take into account?

在使用套接字的情况下,在本地使用套接字时是否有任何推荐的winsock设置/标志?

In the case of using sockets, are there any winsock settings/flags that are recomended when using sockets locally?

推荐答案

一些细微的差异:

如果您没有运行正常的适配器,则套接字将不适用于本地IPC.没有功能正常的适配器的PC有多普遍?好吧,当有人试图向未插入网络或电源的笔记本电脑上的客户演示我们的软件时,我被咬了(因为操作系统禁用了网卡以节省电能)并且无线适配器被禁用了(因为笔记本电脑用户未使用无线).您可以通过安装回送适配器来解决此问题,但这并不理想.

Sockets won't work for local IPC if you don't have a functioning adapter. How common is it to have a PC without a functioning adapter? Well, I got bitten when somebody tried to demonstrate our software to a customer on a laptop that was not plugged in to a network or a power supply (so the OS disabled the network card to save power) and the wireless adapter was disabled (because the laptop user didn't use wireless). You can get around this by installing a loopback adapter but that's not ideal.

防火墙软件可能会导致建立TCP/IP连接的问题.对于本地IPC来说这不应该是一个问题,但是我不相信. 命名管道也可以具有防火墙.

Firewall software can cause problems with establishing TCP/IP connections. It's not supposed to be an issue for local IPC, but I'm not convinced. Named pipes can have firewalls too.

由于创建命名管道或创建命名管道的新实例所需的特权,您可能会遇到问题.例如,我正在使用相同的命名管道运行多个服务器(可能不是一个好主意,但这是为了进行测试),并且其中一些在CreateNamedPipe中失败,因为创建管道的第一台服务器在管理员模式下运行(因为它是从Windows Server 2003启动的) Visual Studio处于管理员"模式),其余的则是从命令行以正常的UAC级别启动的.

You may have issues due to the privileges needed to create named pipes, or to create new instances of named pipes. For instance, I was running multiple servers using the same named pipe (probably not a good idea, but this was for testing) and some failed in CreateNamedPipe because the first server to create the pipe was running in Administrator mode (because it was launched from Visual Studio in Administrator mode) while the rest were launched from the command line with normal UAC level.

尽管鲁本斯提到的文章主要是关于网络上的IPC,但它的确指出了本地命名管道以内核模式运行并且非常快".

Although the article mentioned by Rubens is mostly about IPC over a network, it does make the point that "Local named pipes runs in kernel mode and is extremely fast".

这篇关于Windows上本地IPC的套接字vs命名管道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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