/// <summary> /// Handles the incomming packages. /// Updates the gui depending on the command sent by the server /// </summary> public void InCommingPackages() { try { for ( ; ;) { Package InCommingPackage = PacketParser.ParsePackageString(Connection.GetServerResponse()); Console.WriteLine("client " + PacketParser.MakePackageString(InCommingPackage)); if (InCommingPackage.Type == "userlist") { GUIUpdates.UpdateUserListListBox(InCommingPackage, Connection.LocalIpAddress); } if (InCommingPackage.Type == "newgame") { Console.WriteLine("new game: " + PacketParser.MakePackageString(InCommingPackage)); GUIUpdates.ShowGamePlan(InCommingPackage); } if (InCommingPackage.Type == "gamepattern") { Console.WriteLine("game pattern: " + InCommingPackage.Data); GUIUpdates.UpdateGameAreaForm(InCommingPackage); } } } catch (Exception e) { Console.WriteLine("in comming package: " + e.Message); } }
public void SendPackageToServer(Package PackageToServer) { try { ClientStream = tcpClient.GetStream(); ClientStreamWriter = new StreamWriter(ClientStream); ClientStreamWriter.AutoFlush = true; ClientStreamWriter.WriteLine(PacketParser.MakePackageString(PackageToServer)); } catch (Exception e) { Console.WriteLine("send package: " + e.Message); } }