| Dart.PowerSNMP Namespace > Agent Class > Open Method : Open() Method |
Enables the Agent by binding it to a network address. Events will be raised when SNMP packets are received.
[Visual Basic]
Overloads Public Sub Open() [C#]
public void Open();[C++]
public: void Open(); [C++/CLI]
public:
void Open(); | Exception | Description |
|---|---|
| SocketException | A problem was experienced creating a Socket or binding it to the default host/port. |
| InvalidOperationException | Agent.Socket is already open. |
The Agent cannot communicate until Open is called. Once called, Agent.Socket returns the Socket in use. The "well-known" port 161 is used for default operation. Agent.Close should be used to release socket resources.
The following example demonstrates opening and closing the Agent component.
[Visual Basic]
Private Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click
If (cmdStart.Text = "Start Agent") Then
'Start the Agent
Try 'Open port for receiving requests and sending responses
Agent1.Open()
cmdStart.Text = "Active"
Catch ex As Exception
ShowError(ex.Message)
End Try
Else
'Close Agent
Agent1.Close()
cmdStart.Text = "Start Agent"
End If
End Sub
[C#]
private void cmdStart_Click(object sender, System.EventArgs e)
{
if (cmdStart.Text == "Start Agent")
{
// Start the Agent
try // Open port for receiving requests and sending
responses
{
agent1.Open();
cmdStart.Text = "Active";
}
catch (Exception ex)
{
ShowError(ex.Message);
}
}
else
{
// Close Agent
agent1.Close();
cmdStart.Text = "Start Agent";
}
}
Platforms: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP, Windows Server 2003, Windows Vista
Agent Class | Agent Members | Overload List
Send comments on this topic.
Documentation version 1.2.0.0.
© 2008 Dart Communications. All rights reserved.