Beispiel #1
0
        public void Queue_CanPush()
        {
            IGameUpdate o = new GameUpdate {
                IPAddress = "STRING", GameState = "SomeState"
            };

            _queue.Push(o);
            _queue.Size().ShouldBe(1);
        }
Beispiel #2
0
        // we can 'netstat -an' to see all taken local ports
        public void BeginReceiving()
        {
            while (true)
            {
                // Blocks until a message returns on this socket from a remote host.
                byte[] receiveBytes = _receivingUdpClient.Receive(ref _serverEndpoint);

                string gameState = Encoding.ASCII.GetString(receiveBytes);
                _queue.Push(gameState);
            }
        }
Beispiel #3
0
        private Thread ListenerThread(TcpListener server)
        {
            Thread tcpThread = new Thread(() =>
            {
                byte[] bytes = new byte[4096];
                string data  = null;

                while (true)
                {
                    try
                    {
                        TcpClient tcpClient = server.AcceptTcpClient();

                        data = null;

                        using (NetworkStream stream = tcpClient.GetStream())
                        {
                            int i;

                            while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                            {
                                data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
                                _queue.Push(new GameUpdate {
                                    IPAddress = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address.ToString(), GameState = data
                                });
                            }
                        }
                    } catch (Exception e)
                    {
                        Console.Out.WriteLine(e.Message);
                    }
                }
            });

            return(tcpThread);
        }