public void StartClient() { TcpClient = new TcpClient(); TcpClient.OnCommandSent += (command, bytesSent) => AddLogLine("COMMAND SENT " + command, "Client"); TcpClient.OnConnect += success => AddLogLine("CONNECTED " + success, "Client"); TcpClient.OnFileSent += () => { AddLogLine("FILE SENT", "Client"); TcpClient.WaitForCommand(); }; TcpClient.OnCommandReceived += command => AddLogLine("COMMAND RECEIVED " + command, "Client"); TcpClient.OnFileReceived += fileData => { File.WriteAllBytes(ApplicationPaths.CurrentPath + @"Client.txt", fileData); AddLogLine("FILE RECEIVED", "Client"); TcpClient.SendCommand("MESSAGE:FILE RECEIVED IN CLIENT"); }; TcpClient.Connect(IPAddress.IPv6Loopback, 56000); }
public void TestTwoServerSamePort() { var randomPort = 56000 + new Random().Next(1, 999); var tcpServer1 = new TcpServer(); tcpServer1.Start(randomPort, IPAddress.Loopback); AssertIsTrue(() => tcpServer1.Running); var tcpServer2 = new TcpServer(); tcpServer2.OnErrorOcurred += delegate { }; tcpServer2.Start(randomPort, IPAddress.Loopback); AssertIsTrue(() => !tcpServer2.Running); var tcpClient1 = new TcpClient(); tcpClient1.Connect(IPAddress.Loopback, randomPort); tcpClient1.Disconnect(); tcpServer1.Stop(); }