private void OnDataSent(PacketDataSentEventArgs e) { if (this.DataSent != null) { this.DataSent(this, e); } }
// Send public void Send(byte[] byteStream, DestinationTuple destination) { PacketDataSentEventArgs e = new PacketDataSentEventArgs(byteStream, destination); try { this.ConnectionSocket.SendTo(byteStream, SocketFlags.None, (EndPoint)destination.RemoteEndPoint); this.OnDataSent(e); } catch (ObjectDisposedException exception) { throw exception; } catch (SocketException exception) { if (exception.SocketErrorCode == SocketError.WouldBlock) { this.ConnectionSocket.BeginSendTo(byteStream, 0, byteStream.Length, SocketFlags.None, (EndPoint)destination.RemoteEndPoint, new AsyncCallback(this.SentCallback), e); } else { throw exception; } } }
private void SentCallback(IAsyncResult result) { try { PacketDataSentEventArgs e = (PacketDataSentEventArgs)result.AsyncState; this.ConnectionSocket.EndSend(result); this.OnDataSent(e); } catch (Exception exception) { } }
public void DataSent(object sender, PacketDataSentEventArgs e) { Log4netLogger.Info(MethodBase.GetCurrentMethod().DeclaringType, $"Send {e.Data.Count()} byte(s) 0x{ByteStreamUtil.ByteToHexBit(e.Data)} from {e.Destination.LocalEndPoint} to {e.Destination.RemoteEndPoint}"); }
public void DataSent(object sender, PacketDataSentEventArgs e) { Log4netLogger.Info(MethodBase.GetCurrentMethod().DeclaringType, $"Send {e.Data.Count()} byte(s) 0x{ByteStreamUtil.ByteToHexBit(e.Data)}"); }