jobin

jobin

  • NA
  • 1
  • 0

SOCKET PROGRAMMING..SNMP TRAP LISTNER

Oct 31 2008 1:45 PM
I am trying to create a program to listen to SNMP traps send out by a device randomly and quite frequently.
I am a newbie to network programming. I found out that i have to create an asyncronous connection to the port and then listen to the packet using an event handler. My problem is that my current program only listens to one trap and then stops listening. i have to call it again to start listening again.

------ ----------------------------------My Main program-------------------------------------------------------

SocketAsyncEventArgs e = new SocketAsyncEventArgs();

IPEndPoint Ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 162);
EndPoint Remote = (EndPoint)(sender);


Qumax_Socket.Bind(Ipep);

bool Event_Connect = false;
e.SetBuffer(data,0,200);
e.RemoteEndPoint = Remote;
e.AcceptSocket = Qumax_Socket;

Qumax_Socket.ConnectAsync(e); //CONNECTS ASYNCRONOUSLY


e.Completed += new EventHandler(this.e_Completed); //EVENT HANDLER FOR TRAP RECIEVE
Qumax_Socket.ReceiveAsync(e); //ACTIVATE RECIEVE TRAPS


------ ----------------------------------My Recieve handler---------------------------------------------------------

void e_Completed (object sender, SocketAsyncEventArgs e)
{
////Code to recieve handler..Deleted for now.////
Qumax_Socket.ReceiveAsync(e); //Call recieve handler again.
}

So looking at my recieve handler i need to call the receeve traps again to listen to more than one trap. If "Qumax_Socket.ReceiveAsync(e);" line is missing the program recieves to one trap and stops.

My worry is that there is a time interval between receiving of the first trap and calling the receieve function again during which a trap send by the remote machine would be missed. This time delay is equal to the code in the recieve handler.Is this something to worry about?

Is there a better way to do this with .NET sockets?

Please let me know.

Thanks

Answers (1)