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
|
public void att_serveur()
{
s.Start();
c = s.AcceptTcpClient();
Invoke(new Action(delegate { label1.Text = "Connecté ..."; }));
do
{
b = new byte[100000];
str = c.GetStream();
if (str.Read(b, 0, b.Length) != -1) //verifier s'il ya quelque chose dans le flux de donnees
{
string msg = Encoding.ASCII.GetString(b, 0, b.Length);
if (msg.IndexOf(". ") == 0)
{
Invoke(new Action(delegate { textBox1.Text = msg; }));
}
else
{
img = new Bitmap(new MemoryStream(b));
Invoke(new Action(delegate { pictureBox1.Image = img; }));
}
}
} while (true);
}
public Form1()
{
try
{
s = new TcpListener(12366);
Thread t = new Thread(new ThreadStart(att_serveur));
t.Start();
InitializeComponent();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
} |