예제 #1
0
        public void Update()
        {
            if (State != NetworkClientState.Ready)
            {
                return;
            }

            while (Socket.Available > 0)
            {
                NetworkPacket packet = NetworkPacketSerializer.ReadPacket(Socket);
                ReceiveUpdate(packet);
            }
        }
예제 #2
0
        void OnConnectionEstablished(object sender, SocketAsyncEventArgs e)
        {
            if (e.SocketError != SocketError.Success)
            {
                State = NetworkClientState.Disconnected;
                return;
            }
            NetworkPacketSerializer.WritePacket(new JoinRequestPacket(), Socket);
            var packet  = NetworkPacketSerializer.ReadPacket(Socket);
            var welcome = packet as WelcomePacket;

            if (packet == null)
            {
                throw new Exception("Expected a welcome packet but received something else!");
            }
            Playground = new Playground(welcome.Map);
            RaiseMapChanged(welcome.Map);
            State = NetworkClientState.Ready;
        }