-
-
Save kholbekj/9d902ac7a94b1a5a29fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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