// Called when data received void OnMessage(object sender, NetMQSocketEventArgs e) { e.Socket.ReceiveFrameBytes(out bool hasmore); TopicData topicData = new TopicData { }; if (hasmore) { byte[] bytes = e.Socket.ReceiveFrameBytes(out hasmore); if (bytes.Length == 4) { string msgString = Encoding.UTF8.GetString(bytes, 0, bytes.Length); if (msgString == "PING") { // PING message socket.SendFrame(Encoding.UTF8.GetBytes("PONG")); return; } } else { topicData.MergeFrom(bytes); } } // Invoke callback if (topicData.TopicDataRecord != null) { string topic = topicData.TopicDataRecord.Topic; if (topicdataCallbacks.ContainsKey(topic)) { foreach (Action <TopicDataRecord> callback in topicdataCallbacks[topic]) { callback.Invoke(topicData.TopicDataRecord); } } else { foreach (KeyValuePair <string, List <Action <TopicDataRecord> > > entry in topicdataRegexCallbacks) { Match m = Regex.Match(topic, entry.Key); if (m.Success) { foreach (Action <TopicDataRecord> callback in entry.Value) { callback.Invoke(topicData.TopicDataRecord); } } } } } // catch possible error else if (topicData.Error != null) { Debug.LogError("topicData Error: " + topicData.Error.ToString()); return; } }
// Called when data received void OnMessage(object sender, NetMQSocketEventArgs e) { e.Socket.ReceiveFrameBytes(out bool hasmore); TopicData topicData = new TopicData { }; if (hasmore) { byte[] bytes = e.Socket.ReceiveFrameBytes(out hasmore); if (bytes.Length == 4) { string msgString = Encoding.UTF8.GetString(bytes, 0, bytes.Length); if (msgString == "PING") { // PING message socket.SendFrame(Encoding.UTF8.GetBytes("PONG")); return; } } else { topicData.MergeFrom(bytes); } } // single record if (topicData.TopicDataRecord != null) { this.InvokeTopicCallbacks(topicData.TopicDataRecord); } // list of records if (topicData.TopicDataRecordList != null) { foreach (TopicDataRecord record in topicData.TopicDataRecordList.Elements) { this.InvokeTopicCallbacks(record); } } // catch possible error if (topicData.Error != null) { Debug.LogError("TopicData Error: " + topicData.Error.ToString()); return; } }
// Called when data received void OnMessage(object sender, NetMQSocketEventArgs e) { e.Socket.ReceiveFrameBytes(out bool hasmore); TopicData topicData = new TopicData { }; if (hasmore) { topicData.MergeFrom(e.Socket.ReceiveFrameBytes(out hasmore)); } // Invoke callback if (topicData.TopicDataRecord != null) { string topic = topicData.TopicDataRecord.Topic; if (topicdataCallbacks.ContainsKey(topic)) { topicdataCallbacks[topic].Invoke(topicData.TopicDataRecord); } else { foreach (KeyValuePair <string, Action <TopicDataRecord> > entry in topicdataRegexCallbacks) { Match m = Regex.Match(topic, entry.Key); if (m.Success) { entry.Value.Invoke(topicData.TopicDataRecord); } } } } // catch possible error else if (topicData.Error != null) { Debug.LogError("topicData Error: " + topicData.Error.ToString()); return; } }
// Called when data received void OnMessage(object sender, NetMQSocketEventArgs e) { e.Socket.ReceiveFrameBytes(out bool hasmore); TopicData topicData = new TopicData { }; if (hasmore) { topicData.MergeFrom(e.Socket.ReceiveFrameBytes(out hasmore)); } // Invoke callback if (topicData.TopicDataRecord != null) { topicdataCallbacks[topicData.TopicDataRecord.Topic]?.Invoke(topicData.TopicDataRecord); } // catch possible error else if (topicData.Error != null) { Debug.LogError("topicData Error: " + topicData.Error.ToString()); return; } }