void OnSocketMessageSent(object sender, SocketMessage e) { throw new NotImplementedException(); }
/// <summary> /// Sends a message with data and receiver specified in the message. The MessageSent event /// is fired when the process is completed. The message that was actually sent is passed /// with the event and can be checked for equality with the message that was passed as /// argument to this method. /// </summary> /// <param name="message"></param> public void SendMessage(SocketMessage message) { if (_isWorking) { var saea = _sendingSAEAs.Dequeue(); saea.RemoteEndPoint = message.MessagePeer; saea.SetBuffer(message.MessagePayload, 0, message.MessagePayload.Length); if (!_udpSocket.SendToAsync(saea)) OnSendingMessageComplete(this, saea); } }
/// <summary> /// The callback that is informed about incoming messages. It parses the first 4 byte of /// the messages, retrieving an integer value from it that represents the protocolID of the /// application that this message is for. If one or more apllications are registered for /// this protocol ID the are notified. /// </summary> /// <param name="sender">The <see cref="PeerSocket"/>that received the message</param> /// <param name="e"></param> void OnSocketMessageReceived(object sender, SocketMessage e) { // System.BitConverter is not CLS-compliant, neither is uint (= System.UInt32) int protocolID = e.MessagePayload[3]; protocolID = (protocolID << 8) + e.MessagePayload[2]; protocolID = (protocolID << 8) + e.MessagePayload[1]; protocolID = (protocolID << 8) + e.MessagePayload[0]; var receivers = _connectedApplications.FindAll(x => x.ProtocolID == protocolID); while (receivers.Count > 0) { receivers[receivers.Count - 1].OnMessageReceived(e.MessagePeer, e.MessagePayload); receivers.RemoveAt(receivers.Count - 1); } }