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

  • Home
  • SEARCH
  • 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 6932669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:44:06+00:00 2026-05-27T11:44:06+00:00

Running through some examples about sockets, one I’ve come across is this one and

  • 0

Running through some examples about sockets, one I’ve come across is this one and I’m struggling with the syntax a bit. Here’s the code, it works just fine;

require "socket"

server = TCPServer.new(1234)

loop do
  Thread.start(server.accept) do
    |connection|
    puts "Connection started"
    while line = connection.gets
      break if line =~ /quit/ 
      puts line
      connection.puts "received"
    end

    conneciton.puts "closing the connection"
    connection.close
  end    
end

After a little head scratching I figured out that the server.accept code would wait until a connection is detected before starting a thread that loops until quit is called, then closes it.

What I would like a little help with is how I was supposed to have inferred this from the documentation without noodling around with the code? Am I looking in the wrong place for documentation or is it there in plain sight and I’m just not reading it correctly? Here’s the source I’ve been using;

http://www.ruby-doc.org/stdlib-1.9.2/libdoc/socket/rdoc/TCPServer.html#method-i-accept

  • 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-27T11:44:06+00:00Added an answer on May 27, 2026 at 11:44 am

    The truth is, that documentation could be better.

    That documentation assumes you’re familiar with sockets already—that’s a very similar (maybe even identical) behavior to the POSIX accept call, whose documentation states that if they’re aren’t pending connections and you didn’t explicitly request non-blocking operation “accept() shall block until a connection is present”. (“Block” is UNIX-speak for a particular type of waiting).

    Non-blocking operation in the Ruby class is accept_nonblock (according to the document you linked), so you can infer accept is blocking.

    The Ruby documentation is maintained by volunteers, and I’m sure they’d be happy to accept patches to make it better.

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

Sidebar

Related Questions

So i'm not really sure why this is happening but I'm running through some
I'm running through this tutorial found here: http://vb.net-informations.com/crystal-report/vb.net_crystal_report_from_multiple_tables.htm which teaches how to pass a
I am running through some tests about using ArrayLists and List. Speed is very
I'm running through some memory profiling for my application in SDK 3.2 and I
I'm running some code through FxCop and am currently looking at clearing all of
I've found myself running back through some old 3.5 framework legacy code, and found
I'm following through one of the very early examples in Learning Objective-C on the
I was looking through some code on a project of mine and thinking about
I'm new to ASP.net and I'm currently reading about the SqlDataSource and running through
I'm currently walking myself through some basic MPI examples to refresh my memory (using

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.