Class: RTSPTools::RTSPConnectionTester
- Inherits:
-
Object
- Object
- RTSPTools::RTSPConnectionTester
- Defined in:
- lib/rtsptools.rb
Overview
RTSPConnectionTester is a simple class to test RTSP connectivity. This was intended to be used by applications that need to constantly check the status of RTSP media sources, such as IP Cameras.
Constant Summary collapse
- LOG =
:nodoc:
"[logger] - "- LOG_WARNING =
:nodoc:
LOG + "WARNING: "
- USER_AGENT =
RTSP user agent
"RTSPConnectionTester-beta"- RTSP_VERSION =
Current RTSP version
1.0- RTSP_STATUS_CODE_OK =
RTSP status code OK
200- RTSP_SUCCESSFULL_RESPONSE_LINE =
RTSP Successfull response string
"RTSP/#{RTSP_VERSION} #{RTSP_STATUS_CODE_OK} OK\r\n"- DEFAULT_TIMEOUT =
Default connection timeout
5- RTSP_DEFAULT_PORT =
Default RTSP port
554
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
:nodoc:.
-
#logging ⇒ Object
readonly
:nodoc:.
-
#port ⇒ Object
readonly
:nodoc:.
-
#timeout ⇒ Object
readonly
:nodoc:.
-
#uri ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ RTSPConnectionTester
constructor
Creates an RTSPConnectionTester instance.
-
#test_rtsp_connectivity(options = {}) ⇒ Object
Test connectivity against media source..
Constructor Details
#initialize(params = {}) ⇒ RTSPConnectionTester
Creates an RTSPConnectionTester instance.
Params
-
:uri- An RTSP URI to be tested -
:timeout- A timeout for connection test -
:logging- Set this flag to enable logging
Alternative params
Instead of passing an RTSP URI, you can pass the following parameters, for testing port connectivity only
-
:host- The media source host -
:port- The media source port
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rtsptools.rb', line 53 def initialize(params = {}) @uri = params[:uri] @cseq = 0 if @uri @p_uri = URI(@uri) @host = @p_uri.host @port = @p_uri.port || RTSP_DEFAULT_PORT else @host = params[:host] @port = params[:port] || RTSP_DEFAULT_PORT end raise ArgumentError.new("Missing arguments") unless @host @timeout = params[:timeout] || DEFAULT_TIMEOUT @logging = params[:logging] end |
Instance Attribute Details
#host ⇒ Object (readonly)
:nodoc:
20 21 22 |
# File 'lib/rtsptools.rb', line 20 def host @host end |
#logging ⇒ Object (readonly)
:nodoc:
20 21 22 |
# File 'lib/rtsptools.rb', line 20 def logging @logging end |
#port ⇒ Object (readonly)
:nodoc:
20 21 22 |
# File 'lib/rtsptools.rb', line 20 def port @port end |
#timeout ⇒ Object (readonly)
:nodoc:
20 21 22 |
# File 'lib/rtsptools.rb', line 20 def timeout @timeout end |
#uri ⇒ Object (readonly)
:nodoc:
20 21 22 |
# File 'lib/rtsptools.rb', line 20 def uri @uri end |
Instance Method Details
#test_rtsp_connectivity(options = {}) ⇒ Object
Test connectivity against media source.. When deep_check is set, RTSP protocol is check using OPTIONS message. This method blocks until finishes it test, or timeout exceeds
Options
-
:deep_check
Set this flag to test connectivity using OPTIONS message. You must set an RTSP URI to use this option
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/rtsptools.rb', line 80 def test_rtsp_connectivity( = {}) @deep_check = [:deep_check] initialize_socket() begin @socket.connect_nonblock(@saddress) rescue IO::WaitWritable if IO.select([@socket],[@socket],nil,@timeout) begin @socket.connect_nonblock(@saddress) rescue Errno::EISCONN rescue => error @socket.close raise error end else @socket.close raise "Error: connection timed out after #{@timeout} seconds" end end result = true if (@deep_check) if (@p_uri) () if RTSP_SUCCESSFULL_RESPONSE_LINE != @socket.gets result = false end else if @logging puts LOG_WARNING + "skipping deep_check, since no " \ "RTSP uri was given" end end end @socket.close return result end |