public void SubscriberData(List <string> topics = null) { SubscriberSocket subscriber = Create(addrPoint); Register(subscriber, topics); Task.Factory.StartNew(() => { try { while (true) { string messageTopicReceived = subscriber.ReceiveFrameString(); byte[] dataReceived = subscriber.ReceiveFrameBytes(); if (MyFuncOfFlag.IsEndOfFlag(dataReceived)) { break; } Notify(messageTopicReceived, dataReceived); } } catch { } finally { Unregister(subscriber, topics); } }); }
public void Subscriber <T>(List <string> topics = null) { if (typeof(T) == typeof(byte[])) { SubscriberData(topics); } else if (typeof(T) == typeof(string)) { SubscriberString(topics); } else { SubscriberSocket subscriber = Create(addrPoint); Register(subscriber, topics); Task.Factory.StartNew(() => { try { while (true) { string messageTopicReceived = subscriber.ReceiveFrameString(); byte[] dataReceived = subscriber.ReceiveFrameBytes(); if (MyFuncOfFlag.IsEndOfFlag(dataReceived)) { break; } using (MemoryStream stream = new MemoryStream()) { stream.Write(dataReceived, 0, dataReceived.Length); stream.Seek(0, SeekOrigin.Begin); Notify(messageTopicReceived, (T) new BinaryFormatter().Deserialize(stream)); } } } catch { } finally { Unregister(subscriber, topics); } }); } }