Код: Выделить всё
public void KeepActiveSessionAlive()
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// Enabling keep-alive packets
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
// Configure keep-alive settings (Note: These settinggs are Windows platform-specific)
byte[] keepAliveSettings = new byte[12];
BitConverter.GetBytes((uint)1).CopyTo(keepAliveSettings, 0); // Enable keep-alive
BitConverter.GetBytes((uint)3600000).CopyTo(keepAliveSettings, 4); // Keep-alive time 30000 = (30 seconds), 3600000 = 1 hour
BitConverter.GetBytes((uint)10000).CopyTo(keepAliveSettings, 8); // Keep-alive interval (10 seconds)
// Apply keep-alive settings
socket.IOControl(IOControlCode.KeepAliveValues, keepAliveSettings, null);
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... fter-deplo
Мобильная версия