【问题标题】:Having dotnet core 2.0.0 Socket.Listen() support UNIX Domain Socket?dotnet core 2.0.0 Socket.Listen() 是否支持 UNIX 域套接字?
【发布时间】:2017-11-06 23:24:35
【问题描述】:

根据https://github.com/dotnet/corefx/issues/10981,我从 corefx/src/System.Net.Sockets/tests/FunctionalTests/UnixDomainSocketTest.cs 复制了实现,并在本地使用它,如下所示。 (我在 Ubuntu 上使用 dotnet core 2.0.0)

Socket s = new Socket(AddressFamily.Unix, SocketType.Dgram, ProtocolType.Unspecified);
Console.WriteLine(s.SendBufferSize);
Console.WriteLine(s.ReceiveBufferSize);

var unixSocket = "./my.sock.1";
var ep = new UnixDomainSocketEndPoint(unixSocket);
Console.WriteLine(ep.AddressFamily);

try
{
    System.IO.File.Delete(unixSocket);
    s.Bind(ep);

    s.Listen(5);  // **Operation not supported**

    while(true)
    {
        var newS = s.Accept();

        byte[] content = new byte[1000];
        var result = s.Receive(content);
        Console.WriteLine(result);
        Console.WriteLine(Encoding.Default.GetString(content));
        newS.Close();
    }
}
catch(Exception e)
{
    Console.WriteLine(e.Message);
    Console.WriteLine(e.StackTrace);
    s.Close();
}

例外情况如下:

Operation not supported
   at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
   at System.Net.Sockets.Socket.Listen(Int32 backlog)
   at test01.Program.Main(String[] args) in /home/nonstatic/code/temp/test01/Program.cs:line 106

是否有任何解决方案或解决方法可以让 dotnet core 在 Linux 中构建域套接字服务器?谢谢!

【问题讨论】:

    标签: c# ubuntu .net-core ubuntu-16.04 unix-socket


    【解决方案1】:

    看起来@stephentoub 在您的corresponding GitHub issue 上回复了答案。

    您是否尝试过 SocketType.Stream 而不是 SocketType.Dgram?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-18
      • 2017-02-26
      • 1970-01-01
      • 2010-12-01
      • 2013-05-26
      • 1970-01-01
      相关资源
      最近更新 更多