public KService(ThreadSynchronizationContext threadSynchronizationContext, ServiceType serviceType) { this.ServiceType = serviceType; this.ThreadSynchronizationContext = threadSynchronizationContext; this.startTime = MonoTimeHelper.ClientNow(); this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); // 作为客户端不需要修改发送跟接收缓冲区大小 this.socket.Bind(new IPEndPoint(IPAddress.Any, 0)); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { const uint IOC_IN = 0x80000000; const uint IOC_VENDOR = 0x18000000; uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12; this.socket.IOControl((int)SIO_UDP_CONNRESET, new[] { Convert.ToByte(false) }, null); } }
public KService(ThreadSynchronizationContext threadSynchronizationContext, IPEndPoint ipEndPoint, ServiceType serviceType) { this.ServiceType = serviceType; this.ThreadSynchronizationContext = threadSynchronizationContext; this.startTime = MonoTimeHelper.ClientNow(); this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { this.socket.SendBufferSize = Kcp.OneM * 64; this.socket.ReceiveBufferSize = Kcp.OneM * 64; } this.socket.Bind(ipEndPoint); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { const uint IOC_IN = 0x80000000; const uint IOC_VENDOR = 0x18000000; uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12; this.socket.IOControl((int)SIO_UDP_CONNRESET, new[] { Convert.ToByte(false) }, null); } }