//Recieving information from client private void OnReceiveHost(IAsyncResult ar) { try { Socket.EndReceive(ar); var data = Data; Data = new byte[16384]; Socket.BeginReceive(Data, 0, Data.Length, SocketFlags.None, new AsyncCallback(OnReceiveHost), null); var newData = new byte[data.Length - 1]; Array.Copy(data, 1, newData, 0, data.Length - 1); switch (data[0]) { case 2: Player2 = Serializer.Deserialize(newData) as PlayerTurn; Gm.ActualizeMap(Player2); Gm.ActualizeCharacters(); CheckAndCalculateTurn(); break; case 3: var message = Encoding.UTF8.GetString(newData); Gm.ShowMessage(message); break; default: throw new SystemException("Got bad first byte"); } } catch (SocketException) { Gm.EndOfGame(); } }