Login  
Search All Forums
Dart Home | PowerSNMP for .NET | Custom Development Reply | PowerSNMP for .NET Topics | Forums   
AuthorForum: PowerSNMP for .NET
Topic: How to get request details in SocketException?
renu

From: Eschborn, Germany
Posts: 16
Member Since: 02/17/09
posted May 12, 2011 9:42 AM

Hi all,

I have finally switched from version 1.* to 4.3.1 and now I have the same problem as 2 years ago....

In case of a currently not available agent address I now get a System.Net.Sockets.SocketException. In version 1.*, I received a Dart.TimeoutException containing the original RequestMessage object but the SocketException of course does not have this - how can I get the request belonging to this exception?

renu
K M Drake



From: Utica, NY USA
Posts: 3406
Member Since: 07/14/00
posted May 12, 2011 1:15 PM

Hi,
In most cases, a ManagerSlave.GetResponse call will throw the exception, and this method requires a RequestMessage as a parameter, so it should be readily available.

If this does not help, please send in a very simple code snippet that demonstrates what you are doing to support@dart.com.

Thanks,
-ken
renu

From: Eschborn, Germany
Posts: 16
Member Since: 02/17/09
posted May 13, 2011 10:01 AM

Hi Ken,
please see the code below: in DartManager_Error the GetMessage object is not available.

I'm thinking of keeping track of request-id's sent and response-id's received and then looking for missing response-id's in case of error but as many requests might be sent practically simultaneously and asynchroneously this is not really reliable. Can you help me there?

internal void GetObjectValues(MyObject myObject)
{
  AgentRequest agentRequest = GetAgentRequest(objectRequests, false);

  // AgentRequest is a struct containing
  // - an Agent object with the ipAdress
  // - a GetMessage object named 'request' with request.Tag = myObject;

  DartManager.Start(GetValues, agentRequest);
}
private void GetValues(ManagerSlave slave, object agentRequestAsObject)
{

  AgentRequest agentRequest = (AgentRequest)agentRequestAsObject;
  Agent agent = agentRequest.Agent;
  GetMessage request = agentRequests.GetMessage;
  slave.Socket.ReceiveTimeout = agent.Timeout;

  ResponseMessage response = slave.GetResponse(request, agent.Address);

  // we do not reach this point if an invalid ipAddress was given:
  // (note state object agentRequest)
  DartManager.Marshal(new ResponseMessage[] { response }, MarshalOriginGetValues, agentRequest);
}

private void DartManager_Message(object sender, MessageEventArgs e)
{
  // response received -> normal processing
  ResponseMessage response = (ResponseMessage)e.Messages[0];
  AgentRequest agentRequest = (AgentRequest)e.UserState;
  // original GetMessage:
  GetMessage request = agentRequest.GetMessage;
  // need the Tag object for further processing:
  MyObject myObject = (MyObject)request.Tag;
  // ... further processing
}
private void DartManager_Error(object sender, ErrorEventArgs e)
{
  // problem here!!!!
  // here I would need the original GetMessage object to retrieve it's MyObject Tag object
  // but as I get a System.Net.Sockets.SocketException there is no information
  // about the GetMessage object or even the request-id!
}


Thanks
renu

K M Drake



From: Utica, NY USA
Posts: 3406
Member Since: 07/14/00
posted May 13, 2011 10:32 AM

Hi,
You should be able to put a try...catch around your GetResponse call, and then Marshal the caught exception yourself.

You could create your own Exception type which includes the Request object, if you want.

Hope it helps,
-ken
renu

From: Eschborn, Germany
Posts: 16
Member Since: 02/17/09
posted May 16, 2011 5:42 AM

Hi Ken,
your suggestion works fine, thank you very much!

renu
Reply | PowerSNMP for .NET Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX