Skip to content

Instantly share code, notes, and snippets.

@PatrickLef
Created March 20, 2011 16:51
Show Gist options
  • Save PatrickLef/878447 to your computer and use it in GitHub Desktop.
Save PatrickLef/878447 to your computer and use it in GitHub Desktop.
##
## SERVER (config.ru)
## Start with: thin start -V -R config.ru
app = proc do |env|
[
200,
{
'Content-Type' => 'text/html',
'Content-Length' => '2'
},
['hi']
]
end
run app
##
## CLIENT
##
require 'socket'
socket = TCPSocket.new('0.0.0.0', 3000)
socket.write "GET /first HTTP/1.1\r\nConnection: keep-alive\r\n\r\n"
socket.flush
socket.write "GET /second HTTP/1.1\r\nConnection: close\r\n\r\n"
socket.flush
response = socket.read
socket.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment