/// <summary> /// Sends the message. /// </summary> /// <param name="message">A message.</param> /// <returns><see cref="true"/> if it is Ok, otherwise <see cref="false"/></returns> public bool SendMessage(RtspMessage message) { if (message == null) { throw new ArgumentNullException("message"); } Contract.EndContractBlock(); if (!_transport.Connected) { if (!AutoReconnect) { return(false); } _logger.Warn($"{_sourceId} Reconnect to a client, strange !!"); try { Reconnect(); } catch (SocketException) { // on a pas put se connecter on dit au manager de plus compter sur nous return(false); } } // if it it a request we store the original message // and we renumber it. //TODO handle lost message (for example every minute cleanup old message) if (message is RtspRequest) { RtspMessage originalMessage = message; // Do not modify original message message = message.Clone() as RtspMessage; _sequenceNumber++; message.CSeq = _sequenceNumber; lock (_sentMessage) { _sentMessage.Add(message.CSeq, originalMessage as RtspRequest); } } try { _logger.Debug($"{_sourceId} Send Message"); message.LogMessage(_logger); message.SendTo(_stream); } catch (Exception ex) { _logger.Debug($"{_sourceId} Error Send Message {ex}"); return(false); } return(true); }
/// <summary> /// Sends the message. /// </summary> /// <param name="message">A message.</param> /// <returns><see cref="true"/> if it is Ok, otherwise <see cref="false"/></returns> public bool SendMessage(RtspMessage message) { if (message == null) { throw new ArgumentNullException("message"); } Contract.EndContractBlock(); if (!_transport.Connected) { if (!AutoReconnect) { return(false); } _logger.Warn("Reconnect to a client, strange !!"); try { Reconnect(); } catch (SocketException) { // on a pas put se connecter on dit au manager de plus compter sur nous return(false); } } // if it it a request we store the original message // and we renumber it. //TODO handle lost message (for example every minute cleanup old message) if (message is RtspRequest requestMsg) { // Original message has CSeq set. Make it so. message.CSeq = ++_sequenceNumber; RtspMessage originalMessage = message.Clone() as RtspMessage; ((RtspRequest)originalMessage).ContextData = requestMsg.ContextData; lock (_sentMessage) { _sentMessage.Add(message.CSeq, originalMessage as RtspRequest); } } _logger.Info("Send Message"); message.LogMessage(); message.SendTo(_transport.GetStream()); return(true); }
/// <summary> /// Sends the message. /// </summary> /// <param name="message">A message.</param> /// <returns><see cref="true"/> if it is Ok, otherwise <see cref="false"/></returns> public bool SendMessage(RtspMessage message) { if (message == null) { throw new ArgumentNullException("message"); } // Contract.EndContractBlock(); if (!_transport.Connected) { // _logger.Warn("Reconnect to a client, strange !!"); try { Reconnect(); } catch (SocketException) { // on a pas put se connecter on dit au manager de plus compter sur nous return(false); } } // if it it a request we store the original message // and we renumber it. if (message is RtspRequest) { RtspMessage originalMessage = message; // Do not modify original message message = message.Clone() as RtspMessage; _sequenceNumber++; message.CSeq = _sequenceNumber; lock (_sentMessage) { _sentMessage.Add(message.CSeq, originalMessage as RtspRequest); } } // _logger.Debug("Send Message"); message.LogMessage(); message.SendTo(_stream); return(true); }