Sha256: e31e48313423d1445f92e703afc8f0de6aac2cc01d32b177ffa4c9fcee3c8dd5

Contents?: true

Size: 648 Bytes

Versions: 22

Compression:

Stored size: 648 Bytes

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'tipi'
require 'tipi/websocket'

def ws_handler(conn)
  timer = spin_loop(interval: 1) do
    conn << Time.now.to_s
  end
  while (msg = conn.recv)
    conn << "you said: #{msg}"
  end
rescue Exception => e
  p e
ensure
  timer.stop
end

opts = {
  reuse_addr:  true,
  dont_linger: true,
  upgrade:     {
    websocket: Tipi::Websocket.handler(&method(:ws_handler))
  }
}

HTML = IO.read(File.join(__dir__, 'ws_page.html'))

puts "pid: #{Process.pid}"
puts 'Listening on port 4411...'

Tipi.serve('0.0.0.0', 4411, opts) do |req|
  req.respond(HTML, 'Content-Type' => 'text/html')
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
tipi-0.55 examples/http_ws_server.rb
tipi-0.54 examples/http_ws_server.rb
tipi-0.53 examples/http_ws_server.rb
tipi-0.52 examples/http_ws_server.rb
tipi-0.51 examples/http_ws_server.rb
tipi-0.50 examples/http_ws_server.rb
tipi-0.49 examples/http_ws_server.rb
tipi-0.47 examples/http_ws_server.rb
tipi-0.46 examples/http_ws_server.rb
tipi-0.45 examples/http_ws_server.rb
tipi-0.43 examples/http_ws_server.rb
tipi-0.42 examples/http_ws_server.rb
tipi-0.41 examples/http_ws_server.rb
tipi-0.40 examples/http_ws_server.rb
tipi-0.39 examples/http_ws_server.rb
tipi-0.38 examples/http_ws_server.rb
tipi-0.37.2 examples/http_ws_server.rb
tipi-0.37.1 examples/http_ws_server.rb
tipi-0.37 examples/http_ws_server.rb
tipi-0.36 examples/http_ws_server.rb