public void loadState() { byte[] response = new byte[500]; GetRoomStateReponse res = new GetRoomStateReponse(); byte[] request = serializer.buildMessage(19); Client.client_socket.Send(request); res = serializer.DeAssembleMessage <GetRoomStateReponse>(response); if (res.status == 1) { for (int i = 0; i < res.players.Count; i++) { if (players_[i].Text == "") { players_[i].Text = res.players[i]; } } for (int i = players_.Count; i > res.players.Count; i--) { players_[i - 1].Text = ""; } this.time.Text = res.answerTimeout.ToString(); this.questions.Text = res.questionCount.ToString(); this.players.Text = res.players.Count.ToString(); } }
private void listen() { while (true) { Client.client_socket.ReceiveTimeout = 1; GameStartResponse resS = new GameStartResponse(); GetRoomStateReponse res = new GetRoomStateReponse(); byte[] response = new byte[200]; byte[] code = new byte[1]; int bytes = -1; try { lock (Client.locker) { bytes = Client.client_socket.Receive(code, 1, 0); } } catch { Console.Write("Hello World"); } if (bytes == 0 || bytes == -1) { Client.client_socket.ReceiveTimeout = originalTimeout; byte[] request = serializer.buildMessage(19); lock (Client.locker) { Client.client_socket.Send(request); Client.client_socket.Receive(code, 1, 0); } } if (bytes == 1) { Console.Write("Hello World"); } if (code[0] == 17) { resS = serializer.DeAssembleMessageForThread <GameStartResponse>(response); if (resS.status == 1) { return; } } else { res = serializer.DeAssembleMessageForThread <GetRoomStateReponse>(response); if (res.status == 1) { for (int i = 0; i < res.players.Count; i++) { if (players_[i].Text == "") { players_[i].Text = res.players[i]; } } for (int i = players_.Count; i > res.players.Count; i--) { players_[i - 1].Text = ""; } } } Thread.Sleep(3000); } }