Exemple #1
0
        private void GetClientAction(GameState gameState, Socket socket)
        {
            var gameStateJson = GameStateJsonSerializer.Serialize(gameState);
            var bytes         = Encoding.UTF8.GetBytes(gameStateJson);
            var jsonLength    = bytes.Length;
            var lengthBytes   = BitConverter.GetBytes(jsonLength);

            var state = new GetClientActionPayloadState();

            state.workSocket     = socket;
            state.gameState      = gameState;
            state.gameStateBytes = bytes;

            try
            {
                socket.BeginSend(lengthBytes, 0, lengthBytes.Length, 0,
                                 new AsyncCallback(SendGameStatePayloadCallback), state);
            }
            catch (SocketException e)
            {
                Console.WriteLine(e);
                socket.Close();
            }
        }