void zmqSubThread() { while (app_exit_sub == false && subscriber != null) { try { Msg msg = new Msg(); msg.InitEmpty(); bool dresult = subscriber.TryReceive(ref msg, new TimeSpan(0, 0, 0, 0, 10)); if (dresult) { last_read_time = Helper2.getCurrentTimeSpan(); //if (typeof(SUBTYPE) == typeof(RawData)) //{ // get_raw_bytes = msg.Data; //} //else //{ System.IO.MemoryStream ms = new System.IO.MemoryStream(msg.Data); SUBTYPE result = Serializer.Deserialize <SUBTYPE>(ms); get = result; //} if (app_exit_sub == false) { state = NetworkState.CONNECTED; updateSetupStatus(true); dataTrigger(); } } } catch { } } }
/// <summary> /// Main networking timer /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Main_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { #region TimeCalculations ulong time = Helper2.getCurrentTimeSpan(); last_read_dt = (ulong)Math.Abs((long)(time - last_read_time)); if (last_read_dt > stream_timeout) { read_timeout_error = true; } else { read_timeout_error = false; } last_write_dt = (ulong)Math.Abs((long)(last_write_time2 - last_write_time1)); if (last_write_dt > stream_timeout) { write_timeout_error = true; } else { write_timeout_error = false; } if (last_write_dt > stream_timeout) { last_write_dt = stream_timeout; } if (last_read_dt > stream_timeout) { last_read_dt = stream_timeout; } status_index++; if (status_index % 2 == 0) { if (!string.IsNullOrEmpty(remote_ip) && is_ping_enabled) { ping.SendAsync(remote_ip, ping_timeout_sec, null); } } #endregion if (state == NetworkState.CONNECTED || state == NetworkState.CONNECTING) { timeoutChecker(); } else if (state == NetworkState.SETUP) { setup(); } else if (state == NetworkState.IDLE) { } else if (state == NetworkState.DISCONNECTED) { state = NetworkState.IDLE; } }