Chandra Sekhar wrote in post #986837:
> I am working with SNMP in ruby, I have installed the SNMP library and
> Written two functions for Set and Get request

Do you mean that you are writing an SNMP *client* application in Ruby - 
that is, something which *sends* set and get requests?

> but when i run this
> I am getting below error.
>
> Then I cross-checked again, and notice that "snmp client" is not
> running.

Which "snmp client" are you talking about?

If your ruby code is an snmp client, then it needs to talk to an snmp 
server ("snmp agent"). If this is on a Windows box then you need to 
start the snmp service. You also need to know the shared secret.

> I want to handle this exception. What is the preferred way to do that?
>
> "c:/ruby/lib/ruby/gems/1.8/gems/snmp-1.0.3/lib/snmp/manager.rb:462:
> warning: An existing connection was forcibly closed by the remote host.
> - recvfrom(2)"

That doesn't look like an exception to me - it says "warning"

If you look at manager.rb around line 462, you'll see this code:

    def warn(message)
        trace = caller(2)
        location = trace[0].sub(/:in.*/,'')
        Kernel::warn "#{location}: warning: #{message}"
    end

    def load_modules(module_list, mib_dir)
        module_list.each { |m| @mib.load_module(m, mib_dir) }
    end

    def try_request(request, community=@community, host=@host, 
port=@port)
        (@retries + 1).times do |n|
            send_request(request, community, host, port)
            begin
                Timeout.timeout(@timeout) do
                    return get_response(request)
                end
            rescue Timeout::Error
                # no action - try again
            rescue => e
                warn e.to_s
            end
        end
        raise RequestTimeout, "host #{@config[:Host]} not responding", 
caller
    end

That is: the snmp gem has already caught the exception (rescue => e), 
and turned it into a warning (warn e.to_s); the warn method calls 
Kernel::warn which just prints it out.

The warning message isn't particularly helpful, but it might mean that 
it got an ICMP port unreachable message in response - which means 
there's nothing listening on the SNMP port (udp 161), which in turn 
means you're not running an SNMP agent/service.

You can use wireshark to capture the SNMP packets and their responses, 
to see if that's actually the case.

-- 
Posted via http://www.ruby-forum.com/.