PowerSNMP for .NET CF
Send(MessageBase,String) Method
See Also  Example Send comments on this topic.
Dart.Snmp Namespace > Agent Class > Send Method : Send(MessageBase,String) Method




message
An instance of a ResponseMessage, ReportMessage, TrapMessage or NotificationMessage.
hostNameOrAddress
The name or IP address (in dot notation) of the target SNMP manager.
Send a message to the SNMP manager specified.

Syntax

Visual Basic (Declaration) 
Public Overloads Function Send( _
   ByVal message As MessageBase, _
   ByVal hostNameOrAddress As String _
) As Integer
Visual Basic (Usage)Copy Code
Dim instance As Agent
Dim message As MessageBase
Dim hostNameOrAddress As String
Dim value As Integer
 
value = instance.Send(message, hostNameOrAddress)
C# 
public int Send( 
   MessageBase message,
   string hostNameOrAddress
)
Managed Extensions for C++ 
public: int Send( 
   MessageBase* message,
   string* hostNameOrAddress
) 
C++/CLI 
public:
int Send( 
   MessageBase^ message,
   String^ hostNameOrAddress
) 

Parameters

message
An instance of a ResponseMessage, ReportMessage, TrapMessage or NotificationMessage.
hostNameOrAddress
The name or IP address (in dot notation) of the target SNMP manager.

Exceptions

ExceptionDescription
System.Net.Sockets.SocketExceptionA problem occurred with network resources.
System.InvalidOperationExceptionThe provided message parameter is not a ResponseMessage, ReportMessage, TrapMessage or NotificationMessage.

Example

The following example demonstrates starting a simple agent supporting a MIB variable.
C#Copy Code
private void button1_Click(object sender, EventArgs e)
{
    //Add variable to agent
    agent1.Mib.CreateVariable(NodeName.sysContact, "Kara Thrace");
    agent1.Variables.Values.Add(agent1.Mib.CreateVariable(NodeName.sysContact, "Kara Thrace"));

    //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.CreateDefaultResponse(request), request.Origin);
}
Visual BasicCopy Code
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
    'Add variable to agent
    agent1.Variables.Values.Add(agent1.Mib.CreateVariable(NodeName.sysContact, "Kara Thrace"))

    'Start listening for requests
    agent1.Start(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.CreateDefaultResponse(request), request.Origin)
End Sub

Remarks

The default trap/notification port of 162 is used.

The EncodedMessage property of the message is updated with the encoded message actually sent.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

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