Commit e8688ac
2019-02-08 23:30:51
Changed files (5)
caller.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+curl -i \
+ --include \
+ --no-buffer \
+ --header "Connection: Upgrade" \
+ --header "Upgrade: websocket" \
+ --header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
+ --header "Sec-WebSocket-Version: 13" \
+ http://localhost:9292/
config.ru
@@ -0,0 +1,54 @@
+#app = lambda do |env|
+#io = env['rack.hijack_io']
+#begin
+#io.write("Status: 200\r\n")
+#io.write("Connection: close\r\n")
+#io.write("Content-Type: text/plain\r\n")
+#io.write("\r\n")
+#10.times do |i|
+#io.write("Line #{i + 1}!\n")
+#io.flush
+#sleep 1
+#end
+#ensure
+#io.close
+#end
+#end
+
+#run app
+
+require 'rack'
+require 'puma'
+require 'rack/handler/puma'
+require 'redis'
+
+class Application
+ attr_reader :redis
+
+ def initialize
+ @redis = Redis.new
+ end
+
+ def call(env)
+ if env['rack.hijack?']
+ env['rack.hijack'].call
+ io = env['rack.hijack_io']
+ redis.subscribe("ruby") do |on|
+ on.message do |channel, message|
+ puts message.inspect
+ io.write(message)
+ end
+ end
+ #Thread.new do
+ #loop do
+ #sleep 5
+ #io.write("I'm awake...")
+ #end
+ #end
+ else
+ ['200', {'Content-Type' => 'text/html'}, ['A barebones rack app.']]
+ end
+ end
+end
+
+Rack::Handler::Puma.run Application.new
Gemfile
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+source "https://rubygems.org"
+
+git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
+
+# gem "rails"
+
+gem "rack", "~> 2.0"
+gem 'puma'
+gem 'redis'
Gemfile.lock
@@ -0,0 +1,17 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ puma (3.12.0)
+ rack (2.0.6)
+ redis (4.1.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ puma
+ rack (~> 2.0)
+ redis
+
+BUNDLED WITH
+ 2.0.1
publisher.rb
@@ -0,0 +1,5 @@
+
+require 'redis'
+
+redis = Redis.new
+redis.publish("ruby", "I love ruby")