hello,
I have a client/server application. the server capture picture from
webcam and send it to every client connected to it.the network part
works good and the capture from webcam too. I associate an event when
a capture is done, then every frame of the webcam should be sent to
the client.
but I cannot find a way to send bitmap throught network, of course I
found many method from internet, some doen't work, some work but it's
never stable.
here what I do:
server side:
NetworkStream ns = cl.GetStream(); //cl is my
tcpClient for one connection with client
e.Save(stream, tt[1], encodeurs); // stream is
a MemoryStream
stream.Position = 0;
byte[] buffer = new byte[stream.Length];
stream.Write(buffer , 0, buffer .Length); //now
my picture is in buffer
System.IO.StreamWriter sw = new
System.IO.StreamWriter(ns); //
sw.WriteLine(stream.Length.ToString()); // I
send first the picture's size
sw.Flush();
ns.Write(buffer , 0, buffer.Lenght); //Send
picture
client side:
stream = client.GetStream();
streamReader = new System.IO.StreamReader(stream);
string size = streamReader.ReadLine(); //Get picture size
byte[] buffer = new byte[Convert.ToInt32(size)]; //create
buffer with good size
int nRead = stream.Read(buffer, 0, buffer.Length); //read
the picture
System.IO.MemoryStream ImageDataStream = new
System.IO.MemoryStream();
ImageDataStream.Read(buffer, 0, nRead );
Image img = Image.FromStream(ImageDataStream ); Get the
picture from memoryStream
This method doesn't work good and is not stable.
Is it possible by an other method to skip to send the picture size?
What is the real and best method that works, never failed, to send
picture from webcam by socket in c#?
I'm sure it's possible to skip sending the size but I didn't find any
methods that works!
thanks a lot