SIPSorcery.Net.RTSPClient.SendKeepAlives C# (CSharp) Méthode

SendKeepAlives() private méthode

Sends a keep-alive packet to keep the RTSP RTP connection from being shut.
private SendKeepAlives ( ) : void
Résultat void
        private void SendKeepAlives()
        {
            try
            {
                Thread.CurrentThread.Name = "rtspclient-keepalive";

                // Set the initial pause as half the keep-alive interval.
                Thread.Sleep(RTP_KEEP_ALIVE_INTERVAL * 500);

                while (!_isClosed)
                {
                    _rtspSession.SendRTPRaw(new byte[] { 0x00, 0x00, 0x00, 0x00 });

                    // Also send an OPTIONS request on the RTSP connection to prevent the remote server from timing it out.
                    RTSPRequest optionsRequest = new RTSPRequest(RTSPMethodsEnum.OPTIONS, _url);
                    RTSPHeader optionsHeader = new RTSPHeader(_cseq++, _rtspSession.SessionID);
                    optionsRequest.Header = optionsHeader;

                    System.Diagnostics.Debug.WriteLine(optionsRequest.ToString());

                    var rtspRequestBuffer = Encoding.UTF8.GetBytes(optionsRequest.ToString());
                    _rtspStream.Write(rtspRequestBuffer, 0, rtspRequestBuffer.Length);

                    var buffer = new byte[2048];
                    var bytesRead = _rtspStream.Read(buffer, 0, 2048);

                    if (bytesRead > 0)
                    {
                        System.Diagnostics.Debug.WriteLine(Encoding.UTF8.GetString(buffer, 0, bytesRead));

                        var rtspMessage = RTSPMessage.ParseRTSPMessage(buffer, null, null);

                        if (rtspMessage.RTSPMessageType == RTSPMessageTypesEnum.Response)
                        {
                            var optionsResponse = RTSPResponse.ParseRTSPResponse(rtspMessage);
                            //logger.Debug("RTSP Response received for OPTIONS keep-alive request: " + optionsResponse.StatusCode + " " + optionsResponse.Status + " " + optionsResponse.ReasonPhrase + ".");
                        }
                    }
                    else
                    {
                        logger.Warn("Zero bytes were read from the RTSP client socket in response to an OPTIONS keep-alive request.");
                    }

                    _sendKeepAlivesMRE.Reset();
                    _sendKeepAlivesMRE.WaitOne(RTP_KEEP_ALIVE_INTERVAL * 1000);
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception RTSPClient.SendKeepAlives. " + excp);
            }
        }