Skip to content

Instantly share code, notes, and snippets.

@jasim
Created May 14, 2013 17:41
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 jasim/5577919 to your computer and use it in GitHub Desktop.
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
# 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