public MnlMessage SendMessageSync(ContactNode toNode, Message.MnlMessage msg, bool validate, int timeout) { msg.TranId = GenerateTranId(); ManualResetEventSlim eventReset = new ManualResetEventSlim(); msg.AddCallback((m) => eventReset.Set()); ulong msgId = GetMessageId(toNode.EndPoint.Address, BitConverter.ToUInt16(Encoding.ASCII.GetBytes(msg.TranId), 0)); _messages.AddOrUpdate(msgId, new PendingMnlMessage() { RecipientId = toNode.Id, SentMessage = msg, ValidateId = validate }, (k, v) => v); byte[] rawMsg = msg.ToBytes(); _udpClient.Send(rawMsg, rawMsg.Length, toNode.EndPoint); if (eventReset.Wait(timeout)) { PendingMnlMessage msgFromQueue; if (_messages.TryRemove(msgId, out msgFromQueue)) { return(msgFromQueue.SentMessage); } } return(msg); }
public void SendMessage(IPEndPoint toEndPoint, Message.MnlMessage msg) { byte[] rawMsg = msg.ToBytes(); _udpClient.Send(rawMsg, rawMsg.Length, toEndPoint); }