Skip to content

Instantly share code, notes, and snippets.

@Fonsan
Created May 3, 2010 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fonsan/388614 to your computer and use it in GitHub Desktop.
Save Fonsan/388614 to your computer and use it in GitHub Desktop.
require 'socket'
puts "Please enter host:"
hostname = STDIN.gets.chop # Read host and remove the newline
port = 80
s = TCPSocket.open(hostname, port)
s.write("HEAD / HTTP/1.0\n")
s.write("\n")
while line = s.gets # Read lines from the socket
puts line.chop # And print with platform line terminator
end
s.close
#4. Modify the program TCPClient.java in the book (or write a new program in C or Java) and use it to
#connect to a web server and download a web page using HTTP/1.0. (You don’t have to interpret or
#understand the HTML code you get from it.) If needed, read the specification (RFC) to make sure that
#you get all CR (\r) and LF (\n) in the correct place. The program should be able to take a page request
#from the user (e.g. your favorite home page).
#Output from the program should be either a correct error message (web server not found, page not
#found, access forbidden, etc.) or the number of characters of data it received from the server.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment