我正在使用C++ builderXE與Indy 10.5.7,並試圖從另一個代理snmp接收陷阱。如何使用indy TidSNMP組件陷阱
我沒有介紹如何做接收陷阱的程序的信息。
下面你可以找到我正在嘗試使用的代碼片段。
ReceiveTrap()方法總是返回0,這意味着收到非數據。
我用幾年前使用備用API製作的另一個程序測試了PC配置,並且收到了陷阱,所以我不這樣做,它應該是配置問題。
你有一些帽子的建議我在例行下面錯了嗎? 最好的問候,恩佐
void __fastcall TForm1::LabelReceiveTrapClick(TObject * Sender)
{
static bool status = false;
int ists;
String Fun = "[SimpleReceiveTrap] ";
TSNMPInfo * infoSnmp = 0;
try
{
status = !status;
if (status)
{
std::auto_ptr<TIdSNMP>clientSnmp(new TIdSNMP(NULL));
clientSnmp->Community = "public";
clientSnmp->ReceiveTimeout = 1000;
clientSnmp->Binding->Port = 162;
while (status)
{
Application->ProcessMessages();
ists = clientSnmp->ReceiveTrap();
Mylog(L"%s ReceiveTrap status = [%d]", Fun.c_str(), ists);
if (ists > 0)
{
infoSnmp = clientSnmp->Trap;
}
}
}
}
catch (Exception & ex)
{
Mylog(L"%s ERROR", Fun.c_str(), ex.Message.c_str());
}
}