protected virtual void ReadIncomingPackets() { bool canRead = UdpSocket.Available > 0; if (canRead) { IPEndPoint ep = new IPEndPoint(IPAddress.Any, 0); byte[] data = UdpSocket.Receive(ref ep); NetworkMessage <T> nm = new NetworkMessage <T>(); nm.Sender = ep; nm.Packet = new BytePacket <T>(data); nm.ReceiveTime = DateTime.Now; IncomingMessages.Enqueue(nm); PacketsReceived++; TotalBytesReceived += nm.Packet.Payload.Length; InternalReceiveCount += nm.Packet.Payload.Length; LatestReceiveTimestamp = DateTime.Now; } }
private void WebSocketOnMessageReceived(object sender, MessageReceivedEventArgs e) { Debug.Print("Websocket message received:\n" + e.Message + "\n"); try { var message = JsonConvert.DeserializeObject <SinricMessage>(e.Message); if (!HmacSignature.ValidateMessageSignature(message, SecretKey)) { throw new Exception( "Computed signature for the payload does not match the signature supplied in the message. Message may have been tampered with."); } // add to the incoming message queue. caller will retrieve the messages on their own thread IncomingMessages.Enqueue(message); } catch (Exception ex) { Debug.Print("Error processing message from Sinric:\n" + ex + "\n"); } }
public virtual void HandleMessage(Message mesg) { IncomingMessages.Enqueue(mesg); }