Skip to content
Stefano Costa edited this page Mar 5, 2015 · 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 (#!)

#!/Users/me/.rvm/rubies/ruby-2.1.2/bin/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

Step 2: Run it!

./websocketd --port=8080 ./echo.rb

Clone this wiki locally