protected override void SendRespoce(byte value) { byte[] responce; try { var endPoint = (IPEndPoint)RemoteSocket.LocalEndPoint; byte[] ipBytes = endPoint.Address.GetAddressBytes(); byte[] portBytes = BitConverter.GetBytes((short)endPoint.Port); responce = new byte[] { 5, value, 0, 1, ipBytes[0], ipBytes[1], ipBytes[2], ipBytes[3], portBytes[1], portBytes[0] }; } catch (Exception) { responce = new byte[] { 5, 1, 0, 1, 0, 0, 0, 0, 0, 0 }; } try { int sent = LocalSocket.Send(responce); if (sent > 0) { Dispoce(true); return; } Dispoce(false); } catch { Dispoce(false); } }
public void WhenSendIsCalled_SendingRatePerformanceCounterIsIncremented() { var times = Randomizer.Int32(3, 5); for (var i = 0; i < times; i++) { socket.Send(Message.Create(new AddPeerMessage())); } // sendingRate.Verify(m => m.Increment(1), Times.Exactly(times)); receivingRate.Verify(m => m.Increment(1), Times.Never); }
protected override void SendRespoce(byte value) { try { var result = new byte[] { 0, value, 0, 0, 0, 0, 0, 0 }; int sent = LocalSocket.Send(result); if (value == 0x5a && sent > 0) { Dispoce(true); return; } Dispoce(false); } catch { Dispoce(false); } }
/// <summary> /// Sends the next instruction from the outgoing-queue. /// </summary> protected override void AsyncInstructionSendNext() { base.AsyncInstructionSendNext(); if (!haltActive) { byte[] buffer; buffer = Encoding.UTF8.GetBytes(OutgoingInstructions[0].Encode()); LocalSocket.Send(buffer, 0, buffer.Length, SocketFlags.None); Debug($"Sent Message to {OutgoingInstructions[0].Receiver.ToString()}.", DebugType.Info); Debug(OutgoingInstructions[0].ToString(), DebugType.Info); OutgoingInstructions.RemoveAt(0); } else { Debug("Could not send message. Client is in halt-mode. Waiting for 5 seconds...", DebugType.Error); Thread.Sleep(5000); } }