Created
April 29, 2015 20:32
-
-
Save charlieegan3/864bca4782616be42cb6 to your computer and use it in GitHub Desktop.
ruby server
This file contains hidden or 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' | |
socket = TCPSocket.new('0.0.0.0', 3000) | |
socket.write("hey") | |
p socket.recv(100) |
This file contains hidden or 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' | |
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