public void deletesoc(Socket soc) { try { String[] keys = WMQTOPICList.Keys.ToArray(); foreach (string key in keys) { if (WMQTOPICList[key].ALLsoc.Count > 0) { try { WMQTOPICList[key].ALLsoc.Remove(soc); } catch { } } } int len = WMQueuesoclink.Count; WMQueuesoc[] wmqsoc = new WMQueuesoc[len]; WMQueuesoclink.CopyTo(wmqsoc, 0); foreach (WMQueuesoc wmqs in wmqsoc) { if (wmqs.soc == soc) { WMQueuesoclink.Remove(wmqs); return; } } } catch { } }
public bool EXEC(byte command, string data, System.Net.Sockets.Socket soc) { try { WMQData wmqd = new WMQData(); switch (command) { case 0: RegData rd = Newtonsoft.Json.JsonConvert.DeserializeObject <RegData>(data); if (rd.type == "topic") { rd.soc = soc; addtopicsoc(rd); } else { WMQueuesoc wq = new WMQueuesoc(); wq.token = rd.to; wq.soc = soc; WMQueuesoclink.AddLast(wq); } break; case 1: wmqd = Newtonsoft.Json.JsonConvert.DeserializeObject <WMQData>(data); wmqd.ctime = DateTime.Now; WMQDatalink.AddLast(wmqd); break; case 2: wmqd = Newtonsoft.Json.JsonConvert.DeserializeObject <WMQData>(data); wmqd.ctime = DateTime.Now; addtopic(wmqd); break; } } catch { return(false); } return(true); }
void Queuego() { while (true) { try { if (WMQDatalink.Count > 0) { WMQData wmq = WMQDatalink.First(); if (wmq != null) { int len = WMQueuesoclink.Count; WMQueuesoc[] wmqsoc = new WMQueuesoc[len]; WMQueuesoclink.CopyTo(wmqsoc, 0); bool isok = false; foreach (WMQueuesoc wmqs in wmqsoc) { if (wmq.to == wmqs.token) { isok = Send <WMQData>(wmqs.soc, 0x01, wmq); break; } } if (wmq.ctime.AddMilliseconds(wmq.Validityperiod) > DateTime.Now && isok == false) { WMQDatalink.AddLast(wmq); } WMQDatalink.RemoveFirst(); } } } catch (Exception) { }; System.Threading.Thread.Sleep(10); } }