C#中的Unix套接字 [英] Unix sockets in c#

查看:98
本文介绍了C#中的Unix套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Mono的UnixEndPoint,但是在使用它之前就失败了.我在64位Windows 7系统上运行Xamarind + .net 4.5.

I'm trying to employ Mono's UnixEndPoint, but fail before even getting to use it. I'm running Xamarind + .net 4.5 on a 64bit windows 7 system.

下面的代码证明了没有一种组合有效:

Here's a bit of code proving that not a single combination works:

foreach(SocketType st in Enum.GetValues(typeof(SocketType)))
    foreach(ProtocolType pt in Enum.GetValues(typeof (ProtocolType)))
    {
        try{
            socket = new Socket (AddressFamily.Unix, st, pt);
            Console.WriteLine("{0} {1}", st, pt);
        }
        catch{

        }
    }

基本上,所有组合都会产生某种套接字错误.

Basically, all combinations produce a socket error of some sort.

在这里,有人显然使用了它- mono,c#,套接字,性能-是这应该可以在Windows上工作吗?尝试在WINDOWS上使用UNIX套接字可能只是很愚蠢?

Over here, someone used it apparently - mono, c#, sockets, performance - is this supposed to work on windows at all? I might just be very silly trying to use UNIX sockets on WINDOWS?

推荐答案

我看不出有什么理由期望它在Windows上可以正常工作.

I don't see any reason to expect this to work on Windows.

AddressFamily值由.NET的Socket类直接传递给本机

The AddressFamily value is passed directly by .NET's Socket class to the native WSASocket() function to create the unmanaged socket object. By default, only AddressFamily.InterNetwork and AddressFamily.InterNetworkV6 (corresponding to AF_INET and AF_INET6, respectively) are supported by Windows, unless you have other network providers installed (NetBIOS would be an obvious alternative that might be commonly found on a Windows installation).

从文档中:

当前支持的值为AF_INET或AF_INET6,这是IPv4和IPv6的Internet地址族格式.如果安装了地址族的Windows套接字服务提供程序,则支持地址族的其他选项(例如,AF_NETBIOS与NetBIOS一起使用).

The values currently supported are AF_INET or AF_INET6, which are the Internet address family formats for IPv4 and IPv6. Other options for address family (AF_NETBIOS for use with NetBIOS, for example) are supported if a Windows Sockets service provider for the address family is installed.

AddressFamily.Unix可以在 Unix 机器上运行是有道理的,但是除非您在Windows机器上安装了为该地址族提供特定支持的提供程序,否则它实际上应该在该Windows计算机.

It makes sense that AddressFamily.Unix would work on a Unix machine, but unless you have installed a provider on your Windows machine that provides specific support for that address family, it should in fact fail on that Windows machine.


注意:,从2018年8月开始,Windows对AF_UNIX套接字提供了有限的支持,以允许特定的


Note: as of August 2018, Windows provides limited support for AF_UNIX sockets, to allow for specific Windows Subsystem for Linux scenarios. There are important restrictions, among those being: only stream-oriented sockets are supported; and ancillary data (used e.g. to pass file information or user credentials) is not supported. A given socket can be used to communicate within Windows, within a WSL instance, or between Windows and a WSL instance, but not for multiple of these scenarios.

就目前而言,桌面.NET版本和

For now, it appears that there continues to be no support in desktop .NET version, and only limited support in .NET Core. Once the UnixDomainSocketEndPoint support is finalized in .NET Core, I suppose it's possible that will work its way back to the desktop .NET version.

有关更多详细信息,请参见: https://devblogs.microsoft.com/commandline/af_unix-comes-to -windows/ https://devblogs.microsoft.com/commandline/windowswsl-interop-with -af_unix/

For more details, see: https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/ and https://devblogs.microsoft.com/commandline/windowswsl-interop-with-af_unix/

这篇关于C#中的Unix套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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