Skip to content

Instantly share code, notes, and snippets.

@kholbekj
Created October 3, 2013 12:12
Show Gist options
  • Save kholbekj/9d902ac7a94b1a5a29fb to your computer and use it in GitHub Desktop.
Save kholbekj/9d902ac7a94b1a5a29fb to your computer and use it in GitHub Desktop.
require 'socket'
server = TCPServer.new(1357)
@stories = []
loop do
Thread.start(server.accept) do |client|
puts "log: Client connected from #{client.addr[2]}"
client.puts("Welcome! Would you like to read, or two write?")
response = client.gets.chop
if response.include? "read"
read
puts "log: Client want's to read."
elsif response.include? "write"
write
puts "log: Client want's to write. Precious."
end
client.close
end
end
def read
index = ""
@stories.each do |s,i|
index +="[#{i}]:\t#{s[:title]}<BR>"
end
client.puts index
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment