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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:40:42+00:00 2026-05-27T22:40:42+00:00

TCP sockets are streams, not messages, so berkeley sockets send() function on some systems

  • 0

TCP sockets are streams, not messages, so berkeley sockets send() function on some systems may send less data than required. Since Ruby Socket is very thin wrapper over berkeley sockets, AFAIK Socket#send will behave exactly like berkeley sockets send(). So what is the correct way to send a complete message via Ruby TCP sockets? In python it’s a special function for that called sendall(). But in Ruby i need to manually write code like that:

while (sent = sock.send( data, 0 ) < data.length do
  data = data[ sent..-1 ]
end
  • 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-27T22:40:43+00:00Added an answer on May 27, 2026 at 10:40 pm

    To expand on what danielnegri says, IO.write ends up calling io_binwrite in io.c

    The relevant bit of the ruby source is below (n and len are initially set to the length of your data and offset to 0)

    retry:
    arg.offset = offset; 
    arg.length = n;
    
    if (fptr->write_lock) {
      r = rb_mutex_synchronize(fptr->write_lock, io_binwrite_string, (VALUE)&arg);
    }
    else {
      long l = io_writable_length(fptr, n);
      r = rb_write_internal(fptr->fd, ptr+offset, l);
    }
    if (r == n) return len;
    if (0 <= r) {
      offset += r;
      n -= r;
      errno = EAGAIN;
    }
    if (rb_io_wait_writable(fptr->fd)) {
      rb_io_check_closed(fptr);
      if (offset < RSTRING_LEN(str))
        goto retry;
    }
    return -1L;
    

    As you can see, until it has written all the data it will keep on doing goto retry and trying again. rb_io_wait_writable basically checks that the value of errno is such that one should try again (as opposed to something more fatal) and then calls select to avoid busy-waiting.

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

Sidebar

Related Questions

I am using Csharp tcp sockets to send data between a client and server.
So I want to read http streams using flash tcp sockets. I do not
the XMLHttpRequest object causes two TCP SYN Packets when I try to send some
I am developing this app and i need at some point to send data
I'm trying to send messages (byte arrays) from Node.js to Java via TCP socket
Python, Perl and PHP, all support TCP stream sockets . But exactly how do
I have a Php application using stream_socket_client(), to get data through tcp from a
This pertains to Linux kernel 2.6 TCP sockets. I am sending a large amount
How to use simple TCP/IP sockets connections over/with Net.TCP WCF binding? Idea is –
I'm learning to use raw sockets, and im trying to prase out the tcp

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.