private void ButtonCreate_OnClick(object sender, RoutedEventArgs e) { if (ComboBoxIP.SelectedItem == null || TextBoxGameName.Text == "" || TextBoxPort.Text == "" || TextBoxPseudo.Text == "") { _mainWindow.ShowMessageAsync("Paramètres incorrects", "Veuillez remplir tout les champs."); return; } Uri uri = new Uri("net.tcp://" + ComboBoxIP.SelectedItem + ":" + TextBoxPort.Text + "/" + TextBoxGameName.Text + TextBoxPseudo.Text); WaitJoinWindow waitJoinWindow = new WaitJoinWindow(uri, GetComboBoxColor()); if (waitJoinWindow.ShowDialog() == true) { GameFactory gameFactory = new GameFactory(); BoardView boardView = new BoardView(_container); Core.Game game = gameFactory.CreateGame(Mode.Network, _container, boardView, GetComboBoxColor(), null); _mainWindow.MainControl.Content = new GameView(_mainWindow, game, boardView); } else { // Attention : pratique choquante try { NetworkServiceHost.Close(); } catch (Exception) { ; //Rien à faire (technique de pro) } _mainWindow.ShowMessageAsync("Erreur réseau", "Il y a eu un problème lors de la connexion avec l'autre joueur... Vueillez réessayer."); } }
private void NetworkGameServiceOnClientUriReceived(string uri) { LabelWait.Content = "Configuration de la partie"; EndpointAddress endpointAddress = new EndpointAddress(uri); try { NetworkServiceClient.Create(endpointAddress); } catch (Exception) { NetworkServiceHost.Close(); DialogResult = false; } LabelWait.Content = "Tentative de connexion avec le client"; DialogResult = true; }
private bool Ping() { string testMessage = "42"; NetworkServiceClient.Channel().Echo(testMessage); try { string received = NetworkServiceClient.Channel().Echo(testMessage); if (received != testMessage) { NetworkServiceHost.Close(); return(false); } return(true); } catch (Exception) { NetworkServiceHost.Close(); return(false); } }