PowerSNMP for .NET
Send Method (SnmpBase)
Example 




The SNMP message to send.
An IPEndPoint that specifies the destination of the message.
Send a message to the SNMP manager or agent specified.
Syntax
Public Function Send( _
   ByVal message As MessageBase, _
   ByVal remoteEP As IPEndPoint _
) As Integer
Dim instance As SnmpBase
Dim message As MessageBase
Dim remoteEP As IPEndPoint
Dim value As Integer
 
value = instance.Send(message, remoteEP)
public int Send( 
   MessageBase message,
   IPEndPoint remoteEP
)
public: int Send( 
   MessageBase* message,
   IPEndPoint* remoteEP
) 
public:
int Send( 
   MessageBase^ message,
   IPEndPoint^ remoteEP
) 

Parameters

message
The SNMP message to send.
remoteEP
An IPEndPoint that specifies the destination of the message.

Return Value

The number of bytes sent.
Exceptions
ExceptionDescription
System.Net.Sockets.SocketExceptionA problem occurred using network resources.
Remarks

An agent will typically use this method to communicate with SNMP managers. A Trap1Message or Trap2Message can be sent at any time to indicate an alarm. Also used to reply to a RequestMessage. An agent can receive a GetMessage, GetNextMessage, GetBulkMessage or SetMessage request after Agent.Start or Receive is used. CreateResponse is used to create a ResponseMessage that is sent using this method.

A manager can receive an InformMessage after Manager.Start or Receive is used. CreateResponse is used to create a ResponseMessage that is sent using this method.

The AddressFamily of Socket must match the AddressFamily of remoteEP.

If Socket is null, a new Socket is created on IPAddress.Any or IPAddress.IPv6Any as appropriate for remoteEP. Close should be used as warranted.

If Trap1Message.AgentAddress is not set it will be initialized to the address of Socket.

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

Example
The following example demonstrates how to send traps with the agent.
private void TrapSender_Load(object sender, EventArgs e)
{
    //Set sysObjectId to your enterprise number (for Trap1).
    agent1.Variables.Add(agent1.Mib.GetByNodeName(NodeName.sysObjectID).GetIid(), agent1.Mib.CreateVariable(NodeName.sysObjectID, "1.3.6.1.4.1.52222"));
}

private void buttonSendTrap1_Click(object sender, EventArgs e)
{
    //Send an SNMPv1 Trap
    agent1.Send(new Dart.Snmp.Trap1.warmStart(agent1.Variables[agent1.Mib.GetByNodeName(NodeName.sysObjectID).GetIid()].Value.ToString(), agent1.SysUpTime), myManagerAddress);
}

private void buttonSendTrap2_Click(object sender, EventArgs e)
{
    //Send an SNMPv2 Trap (for SNMPv3, configure warmStart.Security.User)
    agent1.Send(new Dart.Snmp.Trap2.warmStart(agent1.SysUpTime), myManagerAddress);
}
Private Sub TrapSender_Load(ByVal sender As Object, ByVal e As EventArgs)
    'Set sysObjectId to your enterprise number (for Trap1).
    agent1.Variables.Add(agent1.Mib.GetByNodeName(NodeName.sysObjectID).GetIid(), agent1.Mib.CreateVariable(NodeName.sysObjectID, "1.3.6.1.4.1.52222"))
End Sub

Private Sub buttonSendTrap1_Click(ByVal sender As Object, ByVal e As EventArgs)
    'Send an SNMPv1 Trap
    agent1.Send(New Dart.Snmp.Trap1.warmStart(agent1.Variables(agent1.Mib.GetByNodeName(NodeName.sysObjectID).GetIid()).Value.ToString(), agent1.SysUpTime), myManagerAddress)
End Sub

Private Sub buttonSendTrap2_Click(ByVal sender As Object, ByVal e As EventArgs)
    'Send an SNMPv2 Trap (for SNMPv3, configure warmStart.Security.User)
    agent1.Send(New Dart.Snmp.Trap2.warmStart(agent1.SysUpTime), myManagerAddress)
End Sub
See Also

Reference

SnmpBase Class
SnmpBase Members


Documentation Version 4.9
© 2016 Dart Communications. All Rights Reserved.
Send comments on this topic