/// <summary> /// Throws if the message is not generated in communication between given server and client /// </summary> public static DthMessage EnsureSource(this DthMessage message, DthTestServer server, DthTestClient client) { if (message.HostId != server.HostId) { throw new Exception($"{nameof(message.HostId)} doesn't match the one of server. Expected {server.HostId} but actually {message.HostId}."); } return(message); }
public DthTestClient(DthTestServer server) { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(new IPEndPoint(IPAddress.Loopback, server.Port)); _hostId = server.HostId; _networkStream = new NetworkStream(socket); _reader = new BinaryReader(_networkStream); _writer = new BinaryWriter(_networkStream); _messageQueue = new BlockingCollection<DthMessage>(); _readCancellationToken = new CancellationTokenSource(); Task.Run(() => ReadMessage(_readCancellationToken.Token), _readCancellationToken.Token); }
public DthTestClient(DthTestServer server) { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(new IPEndPoint(IPAddress.Loopback, server.Port)); _hostId = server.HostId; _networkStream = new NetworkStream(socket); _reader = new BinaryReader(_networkStream); _writer = new BinaryWriter(_networkStream); _messageQueue = new BlockingCollection <DthMessage>(); _readCancellationToken = new CancellationTokenSource(); Task.Run(() => ReadMessage(_readCancellationToken.Token), _readCancellationToken.Token); }