Salut je suis entrain de programmer une plateforme de discussion mais j'ai un probleme pour envoyer des messages à un client sachant son adresse IP .
dans mon code ci dessous je peux pas envoyer qu'à un seul client

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
 
namespace PlateformeDeDiscussion
{
    class Clients
    {
        private static string reponse = null;
        private static string demande = null;
        public static void demander(string s)
        {
            demande = s;
        }
        public static string reponser()
        {
            return reponse;
        }
        public static void rep()
        {
            reponse = null;
        }
        public void connecter(String Adress, int port)
        {
            try
            {
                TcpClient tcpClient = new TcpClient(Adress, port);
                ThreadPool.QueueUserWorkItem(ecriture,tcpClient);
                using (NetworkStream networkStream = tcpClient.GetStream())
                {
                    using (StreamReader reader = new StreamReader(networkStream))
                    {
                        using (StreamWriter writer = new StreamWriter(networkStream))
                        {
                            writer.AutoFlush = true;
                            while (true)
                            {
                                reponse = reader.ReadLine();
                            }
                        }
                    }
                }
            }
            catch (Exception e) { } //Console.WriteLine(e.Message);
            finally { Serveurs.tclient.Clear(); }
        }
        public void ecriture(object info)
        {
 
            using (TcpClient tcpClient = info as TcpClient)
 
                using (NetworkStream networkStream = tcpClient.GetStream())
                {
                    using (StreamReader reader = new StreamReader(networkStream))
                    {
                        using (StreamWriter writer = new StreamWriter(networkStream))
                        {
                            // flux de sortie non bufferisé
                            writer.AutoFlush = true;
                            while (true)
                            {
                                if (demande != null)
                                    demande += "\r\n";
                                writer.Write(demande);
                                demande = null;
                                Thread.Sleep(50);
                            }
                        }
                    }
                }
 
        }
    }
class Serveurs
    {
        private static string reponse2;
        private static string demande2;
        public static ArrayList tclient = new ArrayList();
       public static List<Socket> mesClients = new List<Socket>();
        public static void demander(string s)
        {
            demande2 = s;
        }
        public static string reponser()
        {
            return reponse2;
        }
        public static void rep()
        {
            reponse2 = null;
        }
        public static void connecter(int port)
        {
            TcpListener ecoute = null;
            try
            {
                ecoute = new TcpListener(IPAddress.Any, port);
                ecoute.Start();
                ThreadPool.SetMinThreads(10, 10);
                ThreadPool.SetMaxThreads(10, 10);
                TcpClient tcpclient = null;
                while (true)
                {
                tcpclient = ecoute.AcceptTcpClient();
                ThreadPool.QueueUserWorkItem(lire, new Clientt() {CanalTcp = tcpclient});
                ThreadPool.QueueUserWorkItem(ecrire, new Clientt() {CanalTcp = tcpclient});
                tclient.Add((tcpclient.Client.RemoteEndPoint as IPEndPoint).Address.ToString());
                }
            }
            catch (Exception ex)
            {
                //Form3 form3 = new Form3();
                //form3.Text = ex.Message;
            }
            finally
            {
                ecoute.Stop();
            }
        }
      public static void lire(Object infos)
        {
            Clientt client = infos as Clientt;
 
 
            try
            {
                using (TcpClient tcpClient=client.CanalTcp)
                {
                    using (NetworkStream networkStream = tcpClient.GetStream())
                    {
                        using (StreamReader reader = new StreamReader(networkStream))
                        {
                            using (StreamWriter writer = new StreamWriter(networkStream))
                            {
                                // writer.AutoFlush = true;
                                while (true)
                                {
 
                                    reponse2 = reader.ReadLine();
 
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Form3 form3 = new Form3();
                //form3.Text = e.Message;
            }
        }
 
 
 
        public static void ecrire(Object infos2)
        {
          Clientt client1 = infos2 as Clientt;
 
            try
            {
                using (TcpClient tcpClient=client1.CanalTcp)
                {
                  using (NetworkStream networkStream = tcpClient.GetStream())
                    {
                        using (StreamReader reader = new StreamReader(networkStream))
                        {
                        using (StreamWriter writer = new StreamWriter (networkStream))
                            {
                                writer.AutoFlush = true;
                                demande2 = null;
                                while (true)
                                {
                                    if (demande2 != null)
                                        demande2 += "\r\n";
                                    writer.Write(demande2);
                                    demande2 = null;
                                    Thread.Sleep(50);
 
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                //Form3 form3 = new Form3();
                //form3.Text = e.Message;
            }
        }
        internal class Clientt
        {
            public TcpClient CanalTcp { get; set; }
            //public int NumClient { get; set; }
        }
    }
}
merci de m'aider.et