Created
May 14, 2013 17:41
-
-
Save jasim/5577919 to your computer and use it in GitHub Desktop.
Using WEBrick's GenericServer to talk over TCP without worrying about socket mechanics
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
# to test, run this file and `nc localhost 34242`, type a line and press enter | |
require 'webrick' | |
s = WEBrick::GenericServer.new(:Port => 34242) | |
trap("INT") { s.shutdown } | |
s.start do |sock| | |
begin | |
incoming=sock.readline | |
rescue EOFError => err | |
break | |
end | |
sock.print(incoming.upcase) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment