PowerSNMP for .NET CF
GetResponse(RequestMessage,IPEndPoint) Method
See Also  Example Send comments on this topic.
Dart.Snmp Namespace > ManagerSlave Class > GetResponse Method : GetResponse(RequestMessage,IPEndPoint) Method




request
An instance of GetMessage, GetNextMessage, GetBulkMessage, SetMessage or InformMessage.
remoteEP
The IPEndPoint specifying the target agent or manager.
Sends a blocking request to the specified agent on the specifed port.

Syntax

Visual Basic (Declaration) 
Public Overloads Function GetResponse( _
   ByVal request As RequestMessage, _
   ByVal remoteEP As IPEndPoint _
) As ResponseMessage
Visual Basic (Usage)Copy Code
Dim instance As ManagerSlave
Dim request As RequestMessage
Dim remoteEP As IPEndPoint
Dim value As ResponseMessage
 
value = instance.GetResponse(request, remoteEP)
C# 
public ResponseMessage GetResponse( 
   RequestMessage request,
   IPEndPoint remoteEP
)
Managed Extensions for C++ 
public: ResponseMessage* GetResponse( 
   RequestMessage* request,
   IPEndPoint* remoteEP
) 
C++/CLI 
public:
ResponseMessage^ GetResponse( 
   RequestMessage^ request,
   IPEndPoint^ remoteEP
) 

Parameters

request
An instance of GetMessage, GetNextMessage, GetBulkMessage, SetMessage or InformMessage.
remoteEP
The IPEndPoint specifying the target agent or manager.

Return Value

The ResponseMessage from the remote host.

Exceptions

ExceptionDescription
System.Net.Sockets.SocketExceptionA problem was experienced using the Socket or the Socket.ReceiveTimeout period has expired.
Dart.Snmp.DecodingExceptionA problem was encountered decoding the Response.
Dart.Snmp.SecurityExceptionA problem was encountered with the Security attributes of the Request or the Response.

Example

The following example demonstrates sending a Get request to an agent and receiving the response.
C#Copy Code
private void button1_Click(object sender, EventArgs e)
{
    //Create and send request on a worker thread
    manager1.Start(manager1_SendGetRequest, manager1.Mib.CreateVariable(NodeName.sysContact));
}

private void manager1_SendGetRequest(Dart.Snmp.ManagerSlave slave, object state)
{
    //Create Get Request
    GetMessage request = new GetMessage();
    request.Community = "public";
    request.Version = SnmpVersion.One;
    request.Variables.Add(state as Variable);

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

    //Marshal message to the UI thread using the Message event
    manager1.Marshal(new ResponseMessage[] { response }, null);
}

private void manager1_Message(object sender, Dart.Snmp.MessageEventArgs e)
{
    //Display info about the first variable in the response, and its value
    Variable var = e.Messages[0].Variables[0] as Variable;
    label1.Text = var.Definition.ToString() + var.Value.ToString();
}
Visual BasicCopy Code
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
	'Create and send request on a worker thread
	manager1.Start(AddressOf manager1_SendGetRequest, manager1.Mib.CreateVariable(NodeName.sysContact))
End Sub

Private Sub manager1_SendGetRequest(ByVal slave As Dart.Snmp.ManagerSlave, ByVal state As Object)
	'Create Get Request
	Dim request As GetMessage = New GetMessage()
	request.Community = "public"
	request.Version = SnmpVersion.One
	request.Variables.Add(CType(IIf(TypeOf state Is Variable, state, Nothing), Variable))

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

	'Marshal message to the UI thread using the Message event
	manager1.Marshal(New ResponseMessage() { response }, Nothing)
End Sub

Private Sub manager1_Message(ByVal sender As Object, ByVal e As Dart.Snmp.MessageEventArgs)
	'Display info about the first variable in the response, and its value
	Dim var As Variable = CType(IIf(TypeOf e.Messages(0).Variables(0) Is Variable, e.Messages(0).Variables(0), Nothing), Variable)
	label1.Text = var.Definition.ToString() & var.Value.ToString()
End Sub

Remarks

This method blocks and does not return until either a response from the agent is received or a socket timeout occurs.

Agents normally listen on port 161, but can be configured to listen on other ports also. If sending an InformMessage to another Manager, port 162 is often used (which is normally open for accepting Trap and Notification messages).

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 4.2
© 2010 Dart Communications. All Rights Reserved.