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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:15:12+00:00 2026-05-16T18:15:12+00:00

I am trying to read an HTTP packet via a socket in ruby, and

  • 0

I am trying to read an HTTP packet via a socket in ruby, and for some reason my code keeps on blocking whilst calling recv

socket = TCPSocket.new("localhost",80)
socket.send r.join("\r\n"), 0
socket.flush
#We're only interested in the string "HTTP/1.1 XXX"
if http_status = get_http_status(socket.recv_nonblock(12))
    if http_status == 200
        $logger.info "Wrote #{message_packet}"
    else
        $logger.warn "Resubmitting message because #{line} is not 200"
        @queue.publish(message) 
    end
end

#Get rid of the rest of the content
the_rest = socket.recv(1000)
while(the_rest != "") do
    the_rest = socket.recv(1000)    
end

From what I understand of recv it should return nothing if there’s no data waiting on the socket?

  • 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-16T18:15:13+00:00Added an answer on May 16, 2026 at 6:15 pm

    The connection could be a keep-alive connection. So, your recv() call wont end by itself. You will need to read the Content-Lenght header, then do a read of that many bytes from the content. After that you can get out of the RECV loop.

    Or alternately, issue the request by setting “Connection: close” header so that the server closes the connection after sending the response.

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

Sidebar

Related Questions

I am trying to read some XML code from a website, and am having
I am trying to read an Http response stream twice via the following: HttpWebResponse
I'm trying to read http://free.freeshoutcast.com:39072/7.html this page, I tried this code, <?php function curl_get_file_contents($URL)
I’m trying to read the HTTP response code from a remote server but am
I'm trying to read my json data, but it crashes. NSString *hostStr = @http://www.myIP.com/notices.php;
I'm trying to read the http-response by ajax request. As an echo-server I use
I'm trying to read a URL using the tutorial : http://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html import java.net.*; import
I am trying to read the public wall posts of: http://www.facebook.com/TheWalkingDeadAMC It is possible
I am working on a vb.net 2.0 application and trying to read HTTP headers.
I am trying to refactor my code (a bunch of core modules and some

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.