Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7551297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:27:25+00:00 2026-05-30T10:27:25+00:00

I’ve developed an MPEG-ts Streamer. It reads the packets from a file and sends

  • 0

I’ve developed an MPEG-ts Streamer. It reads the packets from a file and sends them at the right pace to the receiver.

Now everything works fine excluding that I have some lags quite often. I have searched for every possible error in my code. I have optimized my program quite a bit performance wise.

Now I keep a log with the time it takes the sendto() function to send the packet and I also log the difference between when the packet should have been sent and when it is sent.

I noticed that every time the packets are a lot later than average, the time it took the sendto() to send the previous packet is much higher than normal too.

This indicates me that it is the sendto() that is causing those lags every time it somehow takes longer to send a packet. I am using UDP sockets.

Am I maybe doing something wrong with the sockets? Could it be possible that the socket buffer is full and that it actually takes longer to send the packet? Or am I missing something? Is there maybe a way to accelerate the socket or to make it not fill it’s buffer completely before sending?

As this is meant to stream video I am quite depending on the performance, mostly for HD where the lags happen more often as the amount of packets is much higher.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:27:26+00:00Added an answer on May 30, 2026 at 10:27 am

    There are only two reasons for sendto() to block:

    • Your outgoing UDP buffer is full, and it needs to wait until space frees up
    • The CPU scheduler simply decides to do something else for a while, as it can with any syscall.

    Check the size of your outgoing buffer:

    int buff_size;
    int len = sizeof(buff_size);
    
    err = getsockopt(s,SOL_SOCKET,SO_SNDBUF,(char*)&size,&len);
    

    Some linux systems default to absurdly small send buffers (only a few kilobytes), so you may need to set it to something larger.

    If buffer is larger and sendto() is briefly blocking anyway (how long exactly?) then that’s probably just the cost of doing business. Even on a LAN, and certainly on a WAN, latency is going to vary a lot.

    Update

    To increase the system limit on UDP buffer sizes:

    sysctl -w net.core.wmem_max=1048576
    sysctl -w net.core.rmem_max=1048576
    

    You can make this permanent by adding the following lines to /etc/sysctl.conf:

    net.core.wmem_max=1048576
    net.core.rmem_max=1048576
    

    To take advantage of this within your application, you need to use setsockopt():

    int len, trysize, gotsize;
    len = sizeof(int);
    trysize = 1048576+32768;
    do {
       trysize -= 32768;
       setsockopt(s,SOL_SOCKET,SO_SNDBUF,(char*)&trysize,len);
       err = getsockopt(s,SOL_SOCKET,SO_SNDBUF,(char*)&gotsize,&len);
       if (err < 0) { perror("getsockopt"); break; }
    } while (gotsize < trysize);
    printf("Size set to %d\n",gotsize);
    

    Repeat the same thing for SO_RCVBUF. The loop is important because many systems silently enforce a maximum which is less than the max you set with sysctl and when setsockopt() fails, it leaves the previous value untouched. So you have to try many different values until you get one that sticks. Its also important to not test for (gotsize == trysize) because on some systems the result which is set is not actually the same as the one you requested.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.