Skip to content

Instantly share code, notes, and snippets.

@charlieegan3
Created April 29, 2015 20:32
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 charlieegan3/864bca4782616be42cb6 to your computer and use it in GitHub Desktop.
Save charlieegan3/864bca4782616be42cb6 to your computer and use it in GitHub Desktop.
ruby server
require 'socket'
socket = TCPSocket.new('0.0.0.0', 3000)
socket.write("hey")
p socket.recv(100)
require 'socket'
def handle_connection(client)
puts "New client! #{client}"
client.write("Hello from the server!")
client.close
end
socket = TCPServer.new('0.0.0.0', 3000)
puts "Listening on #{PORT}. Press CTRL+C to cancel."
while client = socket.accept
Thread.new { handle_connection(client) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment