Skip to content

Instantly share code, notes, and snippets.

@oscarsan
Created May 15, 2015 13:53
Show Gist options
  • Save oscarsan/d0819f17b10641d16a0e to your computer and use it in GitHub Desktop.
Save oscarsan/d0819f17b10641d16a0e to your computer and use it in GitHub Desktop.
Ruby tcpsocket server
require 'socket' # Get sockets from stdlib
server = TCPServer.open(5000) # Socket to listen on port 2000
counter = 0;
loop do
client = server.accept # Wait for a client to connect
while line = client.gets # Read lines from socket
puts line # and print them
end
client.puts "Hello this is a test by oscar #{counter}"
puts "client sent something with counter #{counter}"
counter = counter+1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment