В настоящее время я работаю над сервером, который использует поддержку активности, используя Socket.IOControl Но он не работает в dotnet core Linux. Когда я пытаюсь запустить его, я получаю исключение PlatformNotSupportedException
Существует ли кроссплатформенная альтернатива реализации поддержки активности в ядре dotnet?
Пример тестового кода
private static void Main(string[] args)
{
Socket socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
socket.Bind((EndPoint)new IPEndPoint(IPAddress.Loopback, 3178));
socket.Listen(10);
Console.WriteLine("Server: Begin Listening");
socket.BeginAccept(new AsyncCallback(Program.AcceptCallback), (object)socket);
Console.WriteLine("Client: Begin Connecting");
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(new IPEndPoint(IPAddress.Loopback, 3178));
Console.WriteLine("Client: Connected");
Console.WriteLine("Client: Client keepAlive");
Program.SetSocketKeepAliveValues(tcpClient.Client, 1000, 1);
Thread.Sleep(50);
Console.WriteLine("Done");
Console.ReadLine();
}
private static void AcceptCallback(IAsyncResult ar)
{
Socket asyncState = ar.AsyncState as Socket;
try
{
Socket socket = asyncState.EndAccept(ar);
Console.WriteLine("Server: Connection made");
Console.WriteLine("Server: Set keepAlive");
Program.SetSocketKeepAliveValues(socket, 1000, 1);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public static void SetSocketKeepAliveValues(Socket socket, int KeepAliveTime, int KeepAliveInterval)
{
uint structure = 0;
byte[] optionInValue = new byte[Marshal.SizeOf<uint>(structure) * 3];
BitConverter.GetBytes(true ? 1U : 0U).CopyTo((Array)optionInValue, 0);
BitConverter.GetBytes((uint)KeepAliveTime).CopyTo((Array)optionInValue, Marshal.SizeOf<uint>(structure));
BitConverter.GetBytes((uint)KeepAliveInterval).CopyTo((Array)optionInValue, Marshal.SizeOf<uint>(structure) * 2);
socket.IOControl(IOControlCode.KeepAliveValues, optionInValue, (byte[])null);
}
заранее спасибо