Skip to content
Marcus S edited this page Dec 23, 2021 · 7 revisions

Step 1: Where's Ruby?

Type which ruby into the console. Replace the first line of the app below with that path (don't delete the shebang, though (#!)

#!/usr/bin/env ruby
# SIMPLE RUBY ECHO SERVER EXAMPLE
def say(msg)
  STDOUT.puts msg
  STDOUT.flush
end

def input
  STDIN.gets.chomp
end

say 'welcome'
command = ''
while command != 'exit'
  command = input
  say command
end

save it as echo.rb and make it executable:

$ chmod +x ./echo.rb

Step 2: Run it!

./websocketd  --port=8080 ./echo.rb
Clone this wiki locally