Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Here is my problem:
I try to send a lot of data (big images) between 2 PC using UDP socket (UDP is the only choice for Multicast).

I use something like RUDP (Reliable-UDP), basically:
- the Server sends a lot of UDP packet with id (one per image) and packet index
- the Client receives the packets and reconstruct the image using the packet index
- if packets are missing, the client sends an UDP message to server to request the missing packets
- the Server sends the missing packet
this loop of actions is done until the server must send the next image.

When everything works fine, a few number of packets is missing and the network used only 5% of bandwidth.
But sometimes, almost all packets are missing and the network used more than 25% of bandwidth (limitation is due to timeout in my implementation, and this work like I want) and represent sending 5 times the same image!

I tried :
- deactivating anti-virus, firewall
- direct connection

- checking if Windows Filtering Platform (WFP) dropped some packet, but nothing appears in the log when firewall is off.

- If I look the resource monitor on both server and client, network use are identical.

I knows it should be possible because I can connect a device sending twice the data framerate I tried without packet loss.

How can I investigate where the packets are lost/dropped?
Posted
Updated 6-Jul-17 21:40pm
Comments
Richard MacCutchan 24-Apr-15 13:10pm    
Switch to TCP.
Pascal-78 24-Apr-15 13:21pm    
And how do you do "Multicast" with TCP ?
Homero Rivera 24-Apr-15 13:26pm    
Explain "multicast". What are the dynamics between clients and the server?

TCP can definitely "multicast".

How are the clients signaled that there is an image to receive? Or do the clients ask for the images every some time?
Pascal-78 24-Apr-15 13:36pm    
Multicast (http://en.wikipedia.org/wiki/Multicast) is a way to send data (in my case) from 1 PC to many others but not all.
Unicast: 1 to 1
Multicast: 1 to many, many to many
Broadcast: 1 to all.

My current test is made only with 2 PC (1 sender, 1 receiver) but the main goal of my project will use more receivers.

The advantage of Multicast from TCP: it used only 1 send for all the clients where TCP needs 1 send per client. In terms of bandwidth : Multicast does not change the needed bandwidth if the number of clients increase, but TCP will have to use N times the bandwidth for N clients.

This application is similar to an ip-camera sending images to clients, the clients do not ask for image, clients are listening on an opened port for the incoming stream.
Homero Rivera 24-Apr-15 13:43pm    
I understand what a multicast is in networking :)
What I'm wondering is how the clients know there is an image they should be getting? Or are the clients always open with a service to get those images whenever the server sends to them?

Wouldn't it be easier if the clients had an application with a timer, where every so many minutes they checked if the server has any new images? and then download them if there are any? And the download occurred via TCP?

That's what I mean by dynamics.

I think all your clients are being used as servers. Clever, but, evidently you are running into trouble.

If bandwith is an issue, then what should be the real server (the one providing images) could serve the requests one by one and not all at once, by putting come clients requests on hold until it it is their turn.

The solution was too simple:

increase the Socket Option ReCeiVe BUFfer (also named SO_RCVBUF).

by default, this buffer is 8kb, in my case it is the size of one UDP packet. That's mean, when my client reads the packet it must be done before the server sends a new packet or the new packet will be discarded by the IP stack.

I increased the buffer to a bigger value (twice the size of an image) using the setsockopt function:
C++
int rcvbufsize = myBigImageSize*2;
setsockopt(mySocket,SOL_SOCKET,SO_RCVBUF,(char*)&rcvbufsize,sizeof(rcvbufsize));


I increased the speed of my server (by waiting less between each packet) and no packet loss!

Now, I need to optimize the size of this receive buffer.
 
Share this answer
 
v2
I have a similar problem, but I can withdraw images with packets lost.
I solved the problem making following steps:
1. Increasing the socket buffer size as said Pascal-78
2. In the receiver part I made a separate thread that only receives packets
3. Maintain the link live by sending back an acknowledge command every time I receive a command
4. Using select() with a timeout between 10 and 500 microseconds to look for a packet before reading it
5. As my soultion must work also in linux I made following command to allow increase the socket size:
sudo sysctl -w net.core.rmem_max=myMaxImagesize*2

6. I wrote at console a message every time data arrives, but unfortunately windows provokes a great delay writting at console. I solved that by writting this code lines at the beginning of the main() to increase console buffer:
#ifndef __linux__   //Introduce this code at the beginning of main() to increase a lot the speed of cout in windows: 
	char buf[4000]; setvbuf(stdout, buf, _IOFBF, sizeof buf);
#endif
 
Share this answer
 

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