Bonjour tout le monde, je travaille sur application client serveur TCP, je bloque au niveau du serveur, en mode console tout marche bien, mais une fois que j'integre une interface graphique au moment de l'activation de mon serveur je ne peux plus rien faire, ma fenetre devient blanche
sachant que mon serveur marche bien meme avec la fenetre bloqué j'arrive toujours a envoyé et recevoir les donnée.
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 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.IO; using System.Net; using System.Net.Sockets; using System.Windows.Forms; namespace Serveur_Socket_Oracle { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { try { Int32 port = 9050; IPAddress localAddr; if (!textBox1.Text.Equals("")) { localAddr = IPAddress.Parse(textBox1.Text); // TcpListener server = new TcpListener(port); TcpListener server = new TcpListener(localAddr, port); // Start listening for client requests. server.Start(); // Buffer for reading data Byte[] bytes = new Byte[1000]; String data = null; // Enter the listening loop. while (true) { textBox2.Text = "Waiting for a connection...\n "; // Perform a blocking call to accept requests. // You could also user server.AcceptSocket() here. TcpClient client = server.AcceptTcpClient(); textBox2.Text = textBox2.Text + "Connected!\n"; data = null; // Get a stream object for reading and writing NetworkStream stream = client.GetStream(); int i; // Loop to receive all the data sent by the client. while ((i = stream.Read(bytes, 0, bytes.Length)) != 0) { // Translate data bytes to a ASCII string. data = System.Text.Encoding.ASCII.GetString(bytes, 0, i); textBox2.Text = textBox2.Text + String.Format("Received: {0}", data) + "\n"; // Process the data sent by the client. data = "OK"; byte[] msg = System.Text.Encoding.ASCII.GetBytes(data); // Send back a response. stream.Write(msg, 0, msg.Length); textBox2.Text = textBox2.Text + String.Format("Sent: {0}", data) + "\n"; } // Shutdown and end connection client.Close(); } } } catch (SocketException eee) { textBox2.Text = textBox2.Text + "SocketException: {0}"; } } } }
Partager