Created
May 15, 2015 13:53
-
-
Save oscarsan/d0819f17b10641d16a0e to your computer and use it in GitHub Desktop.
Ruby tcpsocket server
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' # 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