PowerSNMP for .NET
SnmpSocket Constructor(SnmpBase)
Example 




The controlling Agent or Manager.
Creates an instance of SnmpSocket bound to IPAddress.Any, port 0 (the ephemeral port).
Syntax
Public Function New( _
   ByVal entity As SnmpBase _
)
Dim entity As SnmpBase
 
Dim instance As New SnmpSocket(entity)
public SnmpSocket( 
   SnmpBase entity
)
public: SnmpSocket( 
   SnmpBase* entity
)
public:
SnmpSocket( 
   SnmpBase^ entity
)

Parameters

entity
The controlling Agent or Manager.
Remarks
When created by the user, Close() should be used to release resources.
Example
The following example demonstrates sending an SNMPv1 Get request to an agent and receiving the response in a single-threaded application.
private void button1_Click(object sender, EventArgs e)
{
    //Bind to a socket to send the GetMessage on
    SnmpSocket managerSocket = new SnmpSocket(manager1);

    //Create Get request
    GetMessage request = new GetMessage();
    request.Variables.Add(manager1.Mib.CreateVariable(NodeName.sysContact));

    //Send request and get response
    ResponseMessage response = managerSocket.GetResponse(request, myAgentAddress);

    //Display info about the first variable in the response, and its value
    Variable vari = response.Variables[0];
    label1.Text = vari.Definition.ToString() + vari.Value.ToString();

    //Close the socket when done
    managerSocket.Close();
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    'Bind to a socket to send the GetMessage on
    Dim managerSocket As New SnmpSocket(manager1)

    'Create Get request
    Dim request As New GetMessage()
    request.Variables.Add(manager1.Mib.CreateVariable(NodeName.sysContact))

    'Send request and get response
    Dim response As ResponseMessage = managerSocket.GetResponse(request, myAgentAddress)

    'Display info about the first variable in the response, and its value
    Dim vari As Variable = response.Variables(0)
    label1.Text = vari.Definition.ToString() & vari.Value.ToString()

    'Close the socket when done
    managerSocket.Close()
End Sub
See Also

Reference

SnmpSocket Class
SnmpSocket Members
Overload List


PowerSNMP for .NET Documentation Version 8.0
© 2024 Dart Communications. All Rights Reserved.
Send comments on this topic