Example #1
0
 public void SendResponse(RtspResponse response)
 {
     if (!_connection.WriteMessage(response))
     {
         LOG.Error($"Failed to write response to client at {_connection.RemoteAddress} \n{response}");
     }
 }
Example #2
0
            public RtspResponse Build()
            {
                var response = new RtspResponse(_status)
                {
                    Body = _body == null ? new byte[0] : Encoding.UTF8.GetBytes(_body.ToString())
                };

                foreach (var entry in _headers)
                {
                    response.Headers.Add(entry.Key, entry.Value);
                }

                return(response);
            }
Example #3
0
        public static RtspMessage CreateNewMessage(string[] parts, IPEndPoint endpoint)
        {
            if (parts == null || parts.Length < 3)
            {
                throw new RtspMessageParseException("Unable to parse invalid RtspMessage.");
            }

            try
            {
                if (StartLineTest.IsMatch(parts[2]))
                {
                    LOG.Debug($"Detected RtspRequest '{parts[0]} {parts[1]} {parts[2]}'");
                    var request = new RtspRequest(parts);
                    request.RemoteEndpoint = endpoint;

                    return(request);
                }
                else if (StartLineTest.IsMatch(parts[0]))
                {
                    LOG.Debug($"Detected RtspResponse '{parts[0]} {parts[1]} {parts[2]}'");
                    var response = new RtspResponse(parts);
                    response.RemoteEndpoint = endpoint;

                    return(response);
                }

                throw new RtspMessageParseException($"Received malformed RTSPMessage start line '{parts[0]} {parts[1]} {parts[2]}'");
            }
            catch (Exception e)
            {
                if (e is RtspMessageParseException)
                {
                    throw e;
                }

                throw new RtspMessageParseException($"Unable to parse RTSP message, reason: {e.Message}", e);
            }
        }