Esempio n. 1
0
        public InterfaceJoueur()
        {
            InitializeComponent();

            serveurAddress = IPAddress.Parse("127.0.0.1");
            TcpClient client = new TcpClient();

            do{
                try
                {
                    client.Connect(serveurAddress, numPort);
                    player = new Joueur.Joueur(client, 0, true);    // création du joueur
                    stream = player.leClient.GetStream();
                    connexionEtablie = true;
                }
                catch (Exception e)
                {
                    MessageBox.Show("Erreur socket client : " + e.Message +'\n' + "Nouvelle tentative de connexion dans 5 secondes.");
                    Thread.Sleep(5000); // on attend 5 seconde
                }
            }while(!connexionEtablie);

            thEcoute = new Thread(Ecoute);
            thEcoute.Start();

            thHorloge = new Thread(TimerNumerique);
        }
Esempio n. 2
0
        private void Tourne()
        {
            while (srvTourne)
            {
                try
                {
                    TcpClient client = myList.AcceptTcpClient();  // On attend qu'un client se connecte

                    String message = "Connection accepted from " + client.Client.RemoteEndPoint + "\r\n";
                    try {
                        Invoke(new Action<String>(addMessage), message);    // noter dans l'historique
                    }
                    catch (InvalidOperationException ex) { MessageBox.Show(ex.Message); }

                    Thread thClient = new Thread(new ParameterizedThreadStart(CommunicationClient));      // créer un thread pour communiquer avec client
                    listOfThClients.Add(thClient);       // ajouter le thread dans la liste

                    int prixTotal = EnvoiImages(client);    // Dès qu'un client se connecte, on lui envoie les photos
                    Joueur.Joueur player = new Joueur.Joueur(client, prixTotal, true);

                    listOfPlayers.Add(player);
                    thClient.Start(player);   // on démarre le thread qui s'occupe de la communication avec le client

                    /*
                     * Pour faciliter le test du jeu :
                     * Affichage du prix total des cadeaux chez le serveur
                     */
                    String prixTot = Convert.ToString(prixTotal);
                    String affPrix = "Montant total des cadeaux : " + prixTot;
                    try
                    {
                        Invoke(new Action<String>(addMessage), affPrix);    // ajouter à l'historique
                    }
                    catch (InvalidOperationException ex) { MessageBox.Show(ex.Message); }
                }
                catch (SocketException) { }
            }
        }