lextudio / sharpsnmplib

C# SNMP Library (#SNMP) - Open source SNMP implementation for C# and .NET
https://sharpsnmp.com
MIT License
358 stars 151 forks source link

How to use retry? #655

Closed lextudio-support closed 1 month ago

lextudio-support commented 1 month ago

Hi there,

In your example programs for testget and testset, you use the retry parameter but I'm a little confused as to how this value gets used. I've got a device that doesn't respond correctly every time, so being able to retry the command a certain number of times would be useful to perform using the library if already existing rather than implementing it at my code side. Is there a clearer example you could give as to how to put this into action?

The code below is what I'm currently using to set a value:

public void Set(string Command, int Val, string Password)
{ 
 Variable test = new Variable(new ObjectIdentifier(Command), new Integer32(Val));
 List<Variable> vList = new List<Variable>(); 
 vList.Add(test); Set(vList, Password); 
} 
public void Set(List<Variable> vList, string Password) 
{
 try 
 { 
  Random RGen = new Random(); 
  SetRequestMessage Request = new SetRequestMessage(RGen.Next(1000, 2000), VersionCode.V1, new OctetString(Password), vList); 
  ISnmpMessage response = Request.GetResponse(SetTimeout, devLocation); 
  if (response.Pdu.ErrorStatus.ToInt32() != 0) 
  { 
   throw ErrorException.Create( "error in response", devLocation.Address, response); 
  } 
 } 
 catch (SnmpException SSE) 
 { 
  throw new Exception(SSE.Details.ToString()); 
 } 
}

Original Reported Date: 2010-06-28T07:29:14.993-07:00 Original CodePlex Discussion Thread ID: 217582

lextudio-support commented 1 month ago

Copied from CodePlex without authors:

Hi,

Retry parameter was defined there. But in order to make the samples simple, it is never used anywhere yet. Unless a simple retry mechanism can be found, it will not be used in those samples.

I suggest you try to write your own retry code. If you find it simple enough, you may share it with others.

Regards,

Lex

Original Posted Date: 2010-07-02T23:43:38.097-07:00

lextudio-support commented 1 month ago

Copied from CodePlex without authors:

Hi there,

Is there a list of the error codes published somewhere - is it possible to distinguish a timeout error?

Regards,

Jamie

Original Posted Date: 2010-07-05T00:49:33.633-07:00

lextudio-support commented 1 month ago

Copied from CodePlex without authors:

Retry can be performed under several scenarios, so I am not sure which are the ones you are interested in. If you only want to retry at timeout, try to capture TimeoutException.

Original Posted Date: 2010-07-06T05:49:58.237-07:00

lextudio-support commented 1 month ago

Marked as Answer Date: 2013-10-06T05:02:39.52-07:00