PowerSNMP for .NET
EncodedMessage Property (MessageBase)

Returns the encoded message.
Public ReadOnly Property EncodedMessage As Byte()
Dim instance As MessageBase
Dim value() As Byte
value = instance.EncodedMessage
public byte[] EncodedMessage {get;}
public: __property byte[]* get_EncodedMessage();
property array<byte>^ EncodedMessage {
   array<byte>^ get();

For messages received asynchronously, this property contains a copy of the original encoded packet. Set when Encode is used.

The following example demonstrates logging request and response messages to disk using the EncodedMessage.
private void button1_Click(object sender, EventArgs e)
    //Create Get Request
    GetMessage request = new GetMessage();

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

    //Log the request and response PDUs
    FileStream file = new FileStream("log.txt", FileMode.Append, FileAccess.Write);
    string requestLabel = "\r\nRequest:\r\n";
    string responseLabel = "\r\nResponse:\r\n";
    file.Write(System.Text.Encoding.Default.GetBytes(requestLabel), 0, requestLabel.Length);
    file.Write(request.EncodedMessage, 0, request.EncodedMessage.Length);
    file.Write(System.Text.Encoding.Default.GetBytes(responseLabel), 0, responseLabel.Length);
    file.Write(response.EncodedMessage, 0, response.EncodedMessage.Length);
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    'Create Get Request
    Dim request As New GetMessage()

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

    'Log the request and response PDUs
    Dim file As New FileStream("log.txt", FileMode.Append, FileAccess.Write)
    Dim requestLabel As String = vbCrLf & "Request:" & vbCrLf
    Dim responseLabel As String = vbCrLf & "Response:" & vbCrLf
    file.Write(System.Text.Encoding.Default.GetBytes(requestLabel), 0, requestLabel.Length)
    file.Write(request.EncodedMessage, 0, request.EncodedMessage.Length)
    file.Write(System.Text.Encoding.Default.GetBytes(responseLabel), 0, responseLabel.Length)
    file.Write(response.EncodedMessage, 0, response.EncodedMessage.Length)
End Sub
See Also


MessageBase Class
MessageBase Members

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