public void Start() { NetworkClient.BeginReceive(NetworkMessageReceived, null); if (LocalNode != null) { Console.WriteLine("Network: Listening on " + NetworkClient.Client.LocalEndPoint); } RetryTimer.Change(10000, 10000); }
/// <summary> /// Stops the discovery. /// </summary> public void StopDiscovery() { Stopped = true; RetryTimer?.Dispose(); RetryTimer = null; foreach (var udpClient in UdpSendClients) { udpClient.Close(); } }
public void Stop() { try { RetryTimer.Dispose(); NetworkClient.Close(); } catch { } }
/// <summary> /// Stops the discovery. /// </summary> public void StopDiscovery() { Stopped = true; if (UdpClient != null) { UdpClient.Close(); UdpClient = null; } if (RetryTimer != null) { RetryTimer.Dispose(); RetryTimer = null; } }
private void MessageTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { RetryTimer.Stop(); if (retryCount >= 3) { return; } if (CommandState == DeviceState.EOESent) { if (LastCtxtForWhichSentEoE != null) { LastCtxtForWhichSentEoE.RequestContext.ResponseQCallback(LastCtxtForWhichSentEoE.Response); retryCount++; RetryTimer.Start(); } } else { throw new ApplicationException("Invalid Retry control flow detected"); } }
public void ProcessOther(CommandContext cmdCxt, BaseMessage categorizedCommand) { //if (AppConfiguration.useSequenceNumber) //{ // int sn = commandBeingProcessed.SeqNum.Value; // if (CommandState == DeviceState.None || commandBeingProcessed.CommandName.Equals("INIT"))//first time or reinit // { // SeqNum = sn; // //CommandState = DeviceState.Ready; // } // else // { // if (sn == SeqNum + 1) // { // SeqNum = sn; // } // else if (sn == SeqNum) // { // CommandState = DeviceState.ErrorSent; // cmdCxt.ResponseQCallback($"Duplicate Sequence number. Received {sn}"); // return; // } // else // { // CommandState = DeviceState.ErrorSent; // cmdCxt.ResponseQCallback($"Sequence number out of order. Received {sn}"); // return; // } // } //} commandBeingProcessed = categorizedCommand; if (IsError && !commandBeingProcessed.CommandName.Equals("INIT")) { cmdCxt.ResponseQCallback(ReceptionError.Generate("2001")); CommandState = DeviceState.ErrorSent; return; } if (commandBeingProcessed.Type == MessageType.Ack) { if (CommandState == DeviceState.Ready) { return;//Duplicate ACK } while (CommandState != DeviceState.EOESent) { Thread.Sleep(0); } RetryTimer.Stop(); LastCtxtForWhichSentEoE = null; retryCount = 0; CommandState = DeviceState.Ready; IsReady = true; return; } if ((CommandState == DeviceState.EOESent || CommandState == DeviceState.CommandResponseSent) && commandBeingProcessed.CommandName.Equals("INIT")) { RetryTimer.Stop(); LastCtxtForWhichSentEoE = null; retryCount = 0; CommandState = DeviceState.Ready; IsReady = true; } else if (!(CommandState == DeviceState.None || CommandState == DeviceState.Ready || CommandState == DeviceState.CommandResponseSent || CommandState == DeviceState.ErrorSent || CommandState == DeviceState.EventSent)) { cmdCxt.ResponseQCallback(ReceptionError.Generate("9001")); CommandState = DeviceState.ErrorSent; return; } commandBeingProcessed.PreProcess(cmdCxt, this); if (commandBeingProcessed.Type == MessageType.Action || commandBeingProcessed.Type == MessageType.Control) { commandBeingProcessed.Process(cmdCxt, this); } }