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 924977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:26:53+00:00 2026-05-15T19:26:53+00:00

I have a problem – I don’t know the amount of data being sent

  • 0

I have a problem – I don’t know the amount of data being sent to my UDP server.

The current code is this – testing in irb:

require 'sockets'
sock = UDPSocket.new
sock.bind('0.0.0.0',41588)

sock.read # Returns nothing
sock.recvfrom(1024) # Requires length of data to be read - I don't know this

I could set recvfrom to 65535 or some other large number but this seems like an unnecessary hack.

recvfrom and recvfrom_nonblock both throw away anything after that length specified.

Am I setting the socket up incorrectly?

  • 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-15T19:26:53+00:00Added an answer on May 15, 2026 at 7:26 pm

    Note that UDP is a datagram protocol, not a stream like TCP. Each read from UDP socket dequeues one full datagram. You might pass these flags to recvfrom(2):

    MSG_PEEK
    
        This  flag  causes  the  receive operation to return
        data from the beginning of the receive queue without
        removing that data from the queue. Thus, a subsequent
        receive call will return the same data.
    
    MSG_WAITALL
    
        This flag requests that the operation block until the
        full request is satisfied. However, the call may still
        return less data than requested if a signal is caught,
        an error or disconnect occurs, or the next data to be
        received is of a different type than that returned.
    
    MSG_TRUNC
    
        Return the real length of the packet, even when it was
        longer than the passed buffer. Only valid for packet sockets.
    

    If you really don’t know how large of a packet you might get (protocol limit is 65507 bytes, see here) and don’t care about doubling the number of system calls, do the MSG_PEEK first, then read exact number of bytes from the socket.

    Or you can set an approximate max buffer size, say 4096, then use MSG_TRUNC to check if you lost any data.

    Also note that UDP datagrams are rarely larger then 1472 – ethernet data size of 1500 minus 20 bytes of IPv4 header minus 8 bytes of UDP header – nobody likes fragmentation.

    Edit:

    Socket::MSG_PEEK is there, for others you can use integer values:

    MSG_TRUNC   0x20
    MSG_WAITALL 0x100
    

    Look into your system headers (/usr/include/bits/socket.h on Linux) to be sure.

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

Sidebar

Related Questions

I have problem with my code. I don't know what am I doing wrong.
I have problem with this code..I want to extract data from flat file and
Have problem while getting data from Memcached on .NET MVC solution. I have this
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with latin chars, here is the code: $stopWords = array('i','a','about','an','and','are','as','at','be','by','com','de','en','for','from','how','in','is','it','la','of','on','or','that','the','this','to','was','what','when','where','who','will','with','und','the','www', 'on',
I have problem with my query on C, I’m using the oci8 driver. This
I have problem while loading data into html select when users press or click
I have problem SIMILAR to preventing form data reposting, but not quite the same
I have problem with code. I have written a function for extracting a parameter,
I have problem with php's preg_match.I want to make something like this : When

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.