Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: UDP packets queuing instead of skipping  (Read 3164 times)

0 Members and 1 Guest are viewing this topic.

MinikPLayer

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
UDP packets queuing instead of skipping
« on: May 04, 2018, 08:56:02 pm »
I'm trying to write a simple F1 2016 telemetry program. ( The game just sends some data through UDP and i'm trying to receive this data in SFML ). For that i'm trying to receive data every x miliseconds ( to decrease CPU usage ) and display it. The fault is, that if the game is running there is no enough CPU time and the receive app should skip some packets, but instead of doing that it's queuing packets and displaying it with a big delay which increase in time. The worst thing is that if i try to increase time between receive, delay is getting worse ( and if i set to receive every 0.5s it displays it every 0.5s, but the data.m_time shows that it's receiving every package, but i don't know why? The packages are sent by the game every ~1/60s ).

part of main.cpp:
sf::Time time;
sf::Clock clock;
UDPSocket socket;
socket.bind(port,ip);
socket.setBlocking(false);
F1datastruct data;  // It contains the variables that are used for data receiving
sf::Packet packet;

while (true)
        {
                packet.clear();
                time = clock.getElapsedTime(); 
                if (time.asMilliseconds() > 50)
                {
                        socket.receive(packet, ip, port);
                        packet >> data.m_time >> data.m_lapTime >> (...) >> data.m_vehicleFlags;
                        cout << endl;
                        cout << "Time: " << data.m_time << endl;
                        cout << "Lap time: " << data.m_lapTime << endl;
            clock.restart();
            time = clock.getElapsedTime();
        }
    }



 

Sorry for my bad english.


EDIT:
Trying to catch it on video:
« Last Edit: May 04, 2018, 09:12:27 pm by MinikPLayer »

Gleade

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: UDP packets queuing instead of skipping
« Reply #1 on: May 05, 2018, 03:20:15 am »
Forgive me if I'm wrong, but I think you are after time stamping your packets & disregarding the older packets that are queued?

MinikPLayer

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: UDP packets queuing instead of skipping
« Reply #2 on: May 05, 2018, 08:17:06 am »
Is it possible to ignore timestamp when receiving?

Sorry if i dont't understand, i'm not very advanced programmer :)
« Last Edit: May 05, 2018, 08:21:44 am by MinikPLayer »

Gleade

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: UDP packets queuing instead of skipping
« Reply #3 on: May 07, 2018, 05:09:25 am »
Check the timestamp of each packet in the queue & only process the most recent one perhaps?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10818
    • View Profile
    • development blog
    • Email
Re: UDP packets queuing instead of skipping
« Reply #4 on: May 07, 2018, 08:35:42 am »
I wouldn't exactly know, but I doubt that there's not enough CPU time to process some packets.

My theory would be that the OS or network driver is caching some packets or similar.
Get out Wireshark and check what's actually going on (then again you won't see local network traffic).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MinikPLayer

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: UDP packets queuing instead of skipping
« Reply #5 on: May 07, 2018, 12:12:42 pm »
Wireshark shows nothing on my local ip :/

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10818
    • View Profile
    • development blog
    • Email
Re: UDP packets queuing instead of skipping
« Reply #6 on: May 07, 2018, 01:07:35 pm »
Yep, do you have an additional PC to try and see the traffic? Localhost traffic isn't routed via the network card and thus doesn't appear in Wireshark. I thought there were some tricks to still see it.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MinikPLayer

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: UDP packets queuing instead of skipping
« Reply #7 on: May 07, 2018, 01:39:42 pm »
Tried it on my laptop, and if i set to receive every 50ms, it gets the same as on PC. Also i have wireshark logs but don't know what to do with them :/

 

anything