【发布时间】: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