KB 600009 Asynchronous support in SharpSnmpLib

Summary

This article describes asynchronous support available in SharpSnmpLib.

In #SNMP 7.0 release, basic async operation support is added in SnmpMessageExtension class. You can use BeginGetResponse and EndGetResponse methods to make asynchronous calls, or use SendAsync to send out traps and notifications.

using System;
using System.Collections.Generic;
using System.Net;
using Lextm.SharpSnmpLib;
using Lextm.SharpSnmpLib.Messaging;
using Lextm.SharpSnmpLib.Security;
 
namespace TestAsyncGet
{
    class Program
    {
        static void Main(string[] args)
        {
            GetRequestMessage message = new GetRequestMessage(0,
                VersionCode.V1,
                new OctetString("public"),
                new List<Variable> {new Variable(new ObjectIdentifier("1.3.6.1.1.1.0"))});
            var endpoint = new IPEndPoint(IPAddress.Loopback, 161);
            message.BeginGetResponse(endpoint, new UserRegistry(), endpoint.GetSocket(), ar => {
                var response = message.EndGetResponse(ar);
                Console.WriteLine(response);
            }, null);
            Console.Read();
        }
    }
}

More Information

N/A

References

N/A

Last edited Mar 14, 2011 at 1:00 PM by lextm, version 1