public static void RunStellaServerInstance() { Console.WriteLine("Enter ip:"); string ip = Console.ReadLine(); int id = 0; // Establish the local endpoint for the socket. IPAddress ipAddress = IPAddress.Parse(ip); IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 20055); StellaServer stellaServer = new StellaServer(); Console.WriteLine("Starting Client, press enter to quit"); stellaServer.Start(localEndPoint, 20056, 0); Console.ReadLine(); stellaServer.Dispose(); }
public void Send_message_SendsMessage() { // Establish the local endpoint for the socket. IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); IPAddress ipAddress = ipHostInfo.AddressList[0]; IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 20055); // Create a server Socket server = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); server.Bind(localEndPoint); server.Listen(2); // Create a SocketConnectionController int clientId = 0; StellaServer stellaServer = new StellaServer(); stellaServer.Start(localEndPoint, 20056, clientId); Socket server_receiver = server.Accept(); Thread.Sleep(1000); byte[] message = Encoding.ASCII.GetBytes("ThisIsAMessage"); byte[] expectedInit = PacketProtocol <MessageType> .WrapMessage(MessageType.Init, BitConverter.GetBytes(clientId)); byte[] expectedMessage = PacketProtocol <MessageType> .WrapMessage(MessageType.Standard, message); // Expected init message byte[] receiveBufferInitMessage = new byte[expectedInit.Length]; server_receiver.Receive(receiveBufferInitMessage); Assert.AreEqual(expectedInit, receiveBufferInitMessage); // Expected Standard message stellaServer.Send(MessageType.Standard, message); byte[] receiveBufferMessage = new byte[expectedMessage.Length]; server_receiver.Receive(receiveBufferMessage); Assert.AreEqual(expectedMessage, receiveBufferMessage); }