PowerSNMP for .NET CF
Send(MessageBase,String,Int32) Method
See Also  Example Send comments on this topic.
Dart.Snmp Namespace > Agent Class > Send Method : Send(MessageBase,String,Int32) 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.
port
May be used to specify a port other than the default port of 162. Managers may be configured to listen for traps on non-default ports.
Send a message to the SNMP manager specified.

Syntax

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

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.
port
May be used to specify a port other than the default port of 162. Managers may be configured to listen for traps on non-default ports.

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 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.