/// <summary> /// The send method for the RTP channel. /// </summary> /// <param name="sendOn">The socket to send on. Can be the RTP or Control socket.</param> /// <param name="dstEndPoint">The destination end point to send to.</param> /// <param name="buffer">The data to send.</param> /// <returns>The result of initiating the send. This result does not reflect anything about /// whether the remote party received the packet or not.</returns> internal virtual SocketError Send(RTPChannelSocketsEnum sendOn, IPEndPoint dstEndPoint, byte[] buffer) { if (m_isClosed) { return(SocketError.Disconnecting); } else if (dstEndPoint == null) { throw new ArgumentException("dstEndPoint", "An empty destination was specified to Send in RTPChannel."); } else if (buffer == null || buffer.Length == 0) { throw new ArgumentException("buffer", "The buffer must be set and non empty for Send in RTPChannel."); } else if (IPAddress.Any.Equals(dstEndPoint.Address) || IPAddress.IPv6Any.Equals(dstEndPoint.Address)) { logger.LogWarning($"The destination address for Send in RTPChannel cannot be {dstEndPoint.Address}."); return(SocketError.DestinationAddressRequired); } else { try { Socket sendSocket = RtpSocket; if (sendOn == RTPChannelSocketsEnum.Control) { LastControlDestination = dstEndPoint; if (m_controlSocket == null) { throw new ApplicationException("RTPChannel was asked to send on the control socket but none exists."); } else { sendSocket = m_controlSocket; } } else { LastRtpDestination = dstEndPoint; } sendSocket.BeginSendTo(buffer, 0, buffer.Length, SocketFlags.None, dstEndPoint, EndSendTo, sendSocket); return(SocketError.Success); } catch (ObjectDisposedException) // Thrown when socket is closed. Can be safely ignored. { return(SocketError.Disconnecting); } catch (SocketException sockExcp) { return(sockExcp.SocketErrorCode); } catch (Exception excp) { logger.LogError($"Exception RTPChannel.Send. {excp}"); return(SocketError.Fault); } } }
public SocketError SendAsync(RTPChannelSocketsEnum sendOn, IPEndPoint dstEndPoint, byte[] buffer) { if (dstEndPoint == null) { throw new ArgumentException("dstEndPoint", "An empty destination was specified to SendAsync in RTPChannel."); } else if (buffer == null || buffer.Length == 0) { throw new ArgumentException("buffer", "The buffer must be set and non empty for SendAsync in RTPChannel."); } try { Socket sendSocket = m_rtpSocket; if (sendOn == RTPChannelSocketsEnum.Control) { LastControlDestination = dstEndPoint; if (m_controlSocket == null) { throw new ApplicationException("RTPChannel was asked to send on the control socket but none exists."); } else { sendSocket = m_controlSocket; } } else { LastRtpDestination = dstEndPoint; } sendSocket.BeginSendTo(buffer, 0, buffer.Length, SocketFlags.None, dstEndPoint, EndSendTo, sendSocket); return(SocketError.Success); } catch (ObjectDisposedException) // Thrown when socket is closed. Can be safely ignored. { return(SocketError.Disconnecting); } catch (SocketException sockExcp) { return(sockExcp.SocketErrorCode); } catch (Exception excp) { logger.LogError($"Exception RTPChannel.SendAsync. {excp}"); return(SocketError.Fault); } }