public void TestCommandParser() { if (ServerY.IsRunning) { ServerY.Stop(); } ServerY.Start(); Console.WriteLine("Socket server Y has been started!"); EndPoint serverAddress = new IPEndPoint(IPAddress.Parse("127.0.0.1"), m_Config.Port); using (Socket socket = CreateClientSocket()) { socket.Connect(serverAddress); Stream socketStream = GetSocketStream(socket); using (StreamReader reader = new StreamReader(socketStream, m_Encoding, true)) using (StreamWriter writer = new StreamWriter(socketStream, m_Encoding, 1024 * 8)) { reader.ReadLine(); string command = string.Format("Hello World ({0})!", Guid.NewGuid().ToString()); writer.WriteLine("ECHO:" + command); writer.Flush(); string echoMessage = reader.ReadLine(); Assert.AreEqual(command, echoMessage); } } }
public void StopServer() { if (ServerX.IsRunning) { ServerX.Stop(); Console.WriteLine("Socket server X has been stopped!"); } if (ServerY != null && ServerY.IsRunning) { ServerY.Stop(); Console.WriteLine("Socket server Y has been stopped!"); } }