/// <summary>发送数据流</summary> /// <param name="udp"></param> /// <param name="stream"></param> /// <param name="remoteEP"></param> /// <returns>返回自身,用于链式写法</returns> public static IUdp Send(this IUdp udp, Stream stream, EndPoint remoteEP = null) { Int64 total = 0; //var size = stream.CanSeek ? stream.Length - stream.Position : udp.BufferSize; var size = 1472; Byte[] buffer = new Byte[size]; while (true) { Int32 n = stream.Read(buffer, 0, buffer.Length); if (n <= 0) { break; } udp.Send(buffer, 0, n, remoteEP); total += n; if (n < buffer.Length) { break; } } return(udp); }
/// <summary>向指定目的地发送信息</summary> /// <param name="udp"></param> /// <param name="buffer">缓冲区</param> /// <param name="remoteEP"></param> /// <returns>返回自身,用于链式写法</returns> public static IUdp Send(this IUdp udp, Byte[] buffer, EndPoint remoteEP = null) { udp.Send(buffer, 0, buffer.Length, remoteEP); return(udp); }