#if !NETFX_CORE using System; using System.Net; using System.Threading.Tasks; namespace Plane.Communication { internal class UdpServerConnection : UdpConnectionBase { private IPEndPoint _remoteEP; private Func> _sendFunc; /// /// 初始化 的实例,并指定远程终结点和发送数据所使用的方法。 /// public UdpServerConnection(IPEndPoint remoteEP, Func> sendFunc) { _remoteEP = remoteEP; _sendFunc = sendFunc; } public override void Close() { IsOpen = false; } public override Task OpenAsync() { IsOpen = true; return TaskUtils.CompletedTask; } protected override async Task SendAsync(byte[] datagram, int bytes) { try { await _sendFunc(datagram, bytes, _remoteEP).ConfigureAwait(false); } catch (Exception ex) { Close(); RaiseExceptionThrown(ex); } } } } #endif