Click here to Skip to main content
14,932,707 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am currently working on a video chat project. I finished the text chat part but I am stuck at the video part. I made the sending part but Don't know how to receive.
Also when I start sending without the receiving code on the other form , weird thing comes to the richtextbox



What I have tried:

//_____Here is the sending code_____


Image bitmap = pictureBox1.Image;
                ImageCodecInfo myImageCodecInfo;
                Encoder myEncoder;
                EncoderParameter myEncoderParameter;
                EncoderParameters myEncoderParameters;

                 myImageCodecInfo = GetEncoderInfo("image/jpeg");
                 myEncoderParameters = new EncoderParameters(1);
                 myEncoder = Encoder.Quality;
                 myEncoderParameter = new EncoderParameter(myEncoder, 5L);
                 myEncoderParameters.Param[0] = myEncoderParameter;

               bitmap.Save("Img.jpg", myImageCodecInfo, myEncoderParameters);
                Image snd = Image.FromFile("Img.jpg");
                string Ip = "127.0.0.1";
                int port = 1111;

                byte[] sndcam = ImageToByteArray(snd);

                IPEndPoint ep = new IPEndPoint(IPAddress.Parse(Ip), port);
                Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                
                 client.Connect(ep);
                 client.SendBufferSize = 1024;
                  for (int pos = 0; pos < sndcam.Length; pos += client.SendBufferSize)
                 {
                int len = sndcam.Length - pos > client.SendBufferSize ? client.SendBufferSize : sndcam.Length - pos;
                byte[] chunk = new byte[len];
                Array.Copy(sndcam, pos, chunk, 0, chunk.Length);
                client.Send(chunk);
                 }
                  client.Close();
<pre lang="c#">
Posted
Comments
BillWoodruff 13-Dec-20 0:12am
   
UDP is a simple protocol compared to TCP, and not as reliable: it does not guarantee packet order. or even that a given packet is received. Use TCP.
Arda Güler 13-Dec-20 9:08am
   
but is there no way to do this in UDP ? I mean I know I should've used TCP but I thought UDP is faster. I just want to see if it would work.
Is there a chance to do this in UDP ?
BillWoodruff 13-Dec-20 9:50am
   
I don't know; based on what I read, I choose to stick with TCP. CodeProject has good resources for TCP.
Richard Deeming 14-Dec-20 4:29am
   
You'd effectively have to implement your own reliability and packet ordering protocols on top of UDP...

...at which point, you've reinvented TCP.

As Bill says, stick with TCP. :)
Arda Güler 14-Dec-20 4:35am
   
Thank you for your reply.Do you think TCP would give me enough speed to prevent delays ?
Thank you
Richard Deeming 14-Dec-20 4:46am
   
That depends on the speed of the network between the users, and what you would consider a "delay". :)

UDP does have some advantages - particularly "multicasting", and reduced buffering overhead at the OS level. But it can be a lot more complicated to implement properly.

networking - TCP vs UDP on video stream - Stack Overflow[^]
Arda Güler 14-Dec-20 5:14am
   
what I meant by delay is our professor said UDP is way faster than TCP and is used more in projects like video chatting because of it's speed. But he is not the brightest teacher I've seen so he could be wrong :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900