//-----------------------------------------------------------------------------------------
        private void CreateNewTcpClient(string username)
        {
            Socket socket = _listener.GetSocket();

            TCPClient client = new TCPClient(socket, username);

            client.AddSerializer(_serializer);
            client.AddListener(_listener);
            client.Start();
            _clientList.Add(client);

            Console.WriteLine("Client Connected!!!");
        }
Beispiel #2
0
        public void ServerTcpClientSendPacket()
        {
            //---------------------------------------------------------------------
            //Setup
            //---------------------------------------------------------------------
            server.Start();
            Thread thread = new Thread(AcceptSocket);

            thread.Start();

            TCP_Config config;

            config.address = "127.0.0.1";
            config.port    = 3515;

            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 3515);
            TcpClient  tcpClient     = new TcpClient();

            tcpClient.Connect(localEndPoint);

            DotNetserialization serializer = new DotNetserialization();
            ServerListenerTCP   listener   = new ServerListenerTCP(config);

            Thread.Sleep(50);

            client.AddListener(listener);
            client.AddSerializer(serializer);

            ChatMessagePacket packet = new ChatMessagePacket("This is a test", "Tester");

            //---------------------------------------------------------------------
            //Run Test
            //---------------------------------------------------------------------
            client.Send(packet);

            //---------------------------------------------------------------------
            //Gather Output
            //---------------------------------------------------------------------

            //---------------------------------------------------------------------
            //Assert
            //---------------------------------------------------------------------
        }
        public void ServerTcpClientAddListener()
        {
            //---------------------------------------------------------------------
            //Setup
            //---------------------------------------------------------------------
            server.Start();
            Thread thread = new Thread(AcceptSocket);

            thread.Start();

            TCP_Config config;

            config.address = "127.0.0.1";
            config.port    = 4514;

            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 11000);
            TcpClient  tcpClient     = new TcpClient();

            tcpClient.Connect(localEndPoint);

            ServerListenerTCP listener = new ServerListenerTCP(config);

            Thread.Sleep(50);

            //---------------------------------------------------------------------
            //Run Test
            //---------------------------------------------------------------------
            client.AddListener(listener);

            //---------------------------------------------------------------------
            //Gather Output
            //---------------------------------------------------------------------

            //---------------------------------------------------------------------
            //Assert
            //---------------------------------------------------------------------
        }