public void RunClient(object ipAddress) { client = new TcpClient(ipAddress.ToString(), 6969); while (true) { JObject received = TcpReadWrite.Read(client); string command = (string)received["command"]; switch (command) { case "id": form.Invoke(new Action(() => form.GetId(TcpProtocol.ReadId(received)))); break; case "questionScores": form.Invoke(new Action(() => form.HandleQuestionsScores(TcpProtocol.QuestionAndScoreParse(received)))); break; case "endScores": form.Invoke(new Action(() => form.HandleEndGame(TcpProtocol.EndScoresParse(received)))); client.GetStream().Close(); client.Close(); return; } } }