|
byte
[] bufferReception = newbyte[sClient.Available];
int
sortie = sClient.Receive(bufferReception);
string
message = System.Text.Encoding.ASCII.GetString(bufferReception,
0, bufferReception.Length);
if
(message == "_s")
//screen
{
tbEnvoyer.Text
= "Début de l'envoie";
int
bytes;
int
i = 0;
// Ouverture d'un flux vers le fichier souhaité.
FileStream
fs = newFileStream("DataFile.dat",
FileMode.Create);
// Création d'un Reader Binaire sur ce flux
BinaryWriter
bw = newBinaryWriter(fs);
//Transformation en tableau de Byte
Byte
[] bufferReceptionImage = newByte[1024];
tbEnvoyer.Text
= "avant le while";
while
( (bytes = (sClient.Receive(bufferReceptionImage, 0,
bufferReceptionImage.Length, SocketFlags.None)))
!= 0)
{
i++;
tbEnvoyer.Text
= "Envoie en cours N° " + i + " : " + bytes;
// Envoi du fichier en retour
bw.Write(bufferReceptionImage,
0, bytes);
bufferReceptionImage
= newByte[1024];
//sClient.Receive(bufferEnvoi, 0, bufferEnvoi.Length, SocketFlags.None);
}
// ICI
BinaryFormatter
bf = newBinaryFormatter();
Bitmap
b = (Bitmap)bf.Deserialize(fs);
tbEnvoyer.Text
= "Fin de l'envoie";
pictureBox1.Image
= (Image)b;
}
else
{
tbEnvoyer.Text
= "Message reçu : "+message;
}
|