Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
chandradeo last edited by
Hi frnds i am trying to develop a redundant udp receiver which should receive the data from two senders. There are two senders which are sending same data at every one second. The client has to receive the data from only one source at a time and display in Widgets.
My problem is that when i receive data at every 1 sec interval then i miss some data and the receive delayed data. Thts why i have to query at every 200ms to get correct data. BUT when i use 200ms timer then i see that receiver is not receiving data from only one source but it receives from second also which should not happen.
static int leddisplay_status =0 ,change_flag1=60,leddisplay_status1=0;
MainWindow::MainWindow(QWidget *parent) :
udpSocketRxCDP = new QUdpSocket(this); udpSocketRxCDP->bind(45454); udpSocketRxCDP1 = new QUdpSocket(this); udpSocketRxCDP1->bind(45455); QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(receiveData())); timer->start(1000);
This happens because the sender sends data at 1000ms interval but the receiver queries for data at every
200ms thts why in between the interval the conditions given in code fails and receiver receives from the second source also.
Can any body please tell me how to solve this problem. Thank u all in advance
mcosta last edited by
IMHO your design is very "error prone"; your problem isn't a receive problem but a refresh problem.
I suggest to:
- receive data once it is avalaible on Socket (connect readyRead() signal) and store received data
- every seconds choose which data show in your GUI and clear stored values
In this way you're sure to not lost data and to show the last arrived values.