根据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核心在Linux中构建域套接字服务器?谢谢!
答案 0 :(得分:3)
看起来@stephentoub在你的corresponding GitHub issue上回复了答案。
您是否尝试使用SocketType.Stream而不是SocketType.Dgram?