1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
   | public server()
        {
            InitializeComponent();
 
            // on initialise la pictureBox
            init_pb_webcam();
 
			// initialise et actualise la liste des hôtes
            init_dg_hotes();
            actualise_dg_hotes();
        }
 
        private void server_Load(object sender, EventArgs e)
        {
            Start();
        }
 
        /// <summary>
        /// démarre le mode multi-tâches et les sockets
        /// </summary>
        public void Start()
        {
            // on cherche notre adresse ip
            ip_serveur = AdresseIpLocale(Dns.GetHostName());
 
            // création de la socket
            Socket CurrentClient = null;
            ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
 
            try
            {
                // On lie la socket au point de communication
                ServerSocket.Bind(new IPEndPoint(ip_serveur, 8000));
 
                //On la positionne en mode "écoute"
                ServerSocket.Listen(10);
 
                // on vérifie que les hôtes sont toujours connectés
                Thread pingPongThread = new Thread(new ThreadStart(CheckIfStillConnected));
                pingPongThread.Start();
 
                // Boucle infinie
                while (true)
                {
                    // L'exécution du thread courant est bloquée jusqu'à ce qu'un nouveau client se connecte
                    CurrentClient = ServerSocket.Accept();
                    if (!acceptList.Contains(CurrentClient))
                    {
                        acceptList.Add(CurrentClient);
                    }
                }
            }
            catch (SocketException E)
            {
                Console.WriteLine(E.Message);
            }
        } |