PowerSNMP for .NET
Start(RequestReceived,Object) Method
Example 




A RequestReceived delegate specifying the method to execute when a RequestMessage is received.
Object to pass to the callback method; can be null.
Starts receiving SNMP requests asynchronously, invoking the specified callback method on an IO completion thread as each RequestMessage is received.
Syntax
Public Overloads Sub Start( _
   ByVal callback As RequestReceived, _
   ByVal state As Object _
) 
Dim instance As Agent
Dim callback As RequestReceived
Dim state As Object
 
instance.Start(callback, state)
public void Start( 
   RequestReceived callback,
   object state
)
public: void Start( 
   RequestReceived* callback,
   Object* state
) 
public:
void Start( 
   RequestReceived^ callback,
   Object^ state
) 

Parameters

callback
A RequestReceived delegate specifying the method to execute when a RequestMessage is received.
state
Object to pass to the callback method; can be null.
Remarks

Use this method to receive SNMP requests from SNMP managers. It is possible for the RequestReceived callback method to be invoked concurrently on multiple IO completion threads, so its code should be thread-safe.

The socket is bound to the default IPv4 interface and port 161 if Transport is set to Transport.UDP or port 10161 if Transport is set to Transport.DTLS

The socket is bound to the first local IPv4 network interface on port 161 and will receive datagrams sent to IPAddress.Broadcast.

This method creates a new SocketBase.Socket. Use multiple Agent instances to accept SNMP requests on multiple sockets.

Unhandled exceptions thrown on the IO Completion thread are caught and reported by the Error event.

Scripting applications should use Receive instead.

Example
The following example demonstrates starting a simple agent with one variable.
private void button1_Click(object sender, EventArgs e)
{
    //Add a variable to the agent
    agent1.Variables.Add(agent1.Mib.GetByNodeName(NodeName.sysContact).GetIid(),
        agent1.Mib.CreateVariable(NodeName.sysContact, "Systems Admin"));

    //Start listening for requests
    agent1.Start(agent1_MessageReceived, null);
}

private void agent1_MessageReceived(Agent agent, RequestMessage request, object state)
{
    //Create and send a response whenever a request is received
    agent1.Send(agent1.CreateResponse(request), request.Origin);
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    'Add a variable to the agent
    agent1.Variables.Add(agent1.Mib.GetByNodeName(NodeName.sysContact).GetIid(), agent1.Mib.CreateVariable(NodeName.sysContact, "Systems Admin"))

    'Start listening for requests
    agent1.Start(AddressOf agent1_MessageReceived, Nothing)
End Sub

Private Sub agent1_MessageReceived(ByVal agent As Agent, ByVal request As RequestMessage, ByVal state As Object)
    'Create and send a response whenever a request is received
    agent1.Send(agent1.CreateResponse(request), request.Origin)
End Sub
See Also

Reference

Agent Class
Agent Members
Overload List

6.1.1.2
PowerSNMP for .NET Documentation Version 7.0
© 2023 Dart Communications. All Rights Reserved.
Send comments on this topic