Skip to content

Instantly share code, notes, and snippets.

@oneup
Created July 15, 2009 10:43
Show Gist options
  • Save oneup/147638 to your computer and use it in GitHub Desktop.
Save oneup/147638 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
#
# Generic TCP Server Example
require "GServer"
class Root < GServer
def initialize(port=10001, *args)
super(port, *args)
end
def serve(io)
io.puts(Time.now.to_i)
end
end
server = Root.new
server.audit = true # Turn logging on.
server.start
# *** Now point your browser to http://localhost:10001 to see it working ***
# See if it's still running.
GServer.in_service?(10001) # -> true
server.stopped? # -> false
# Shut the server down gracefully.
server.shutdown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment