Sha256: 2f849df907ef7165e65e4a82247d3c0ae1e6f3b2af287bb9b956a17cd5a12a26

Contents?: true

Size: 799 Bytes

Versions: 11

Compression:

Stored size: 799 Bytes

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'tipi'
require 'localhost/authority'

def ws_handler(conn)
  timer = spin do
    throttled_loop(1) do
      conn << Time.now.to_s
    rescue StandardError
      nil
    end
  end
  while (msg = conn.recv)
    puts "msg: #{msg}"
    # conn << "you said: #{msg}"
  end
ensure
  timer.stop
end

authority = Localhost::Authority.fetch
opts = {
  reuse_addr:     true,
  dont_linger:    true,
  secure_context: authority.server_context,
  upgrade:        {
    websocket: Polyphony::Websocket.handler(&method(:ws_handler))
  }
}

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

puts "pid: #{Process.pid}"
puts 'Listening on port 1234...'
Tipi.serve('0.0.0.0', 1234, opts) do |req|
  req.respond(HTML, 'Content-Type' => 'text/html')
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
tipi-0.38 examples/https_wss_server.rb
tipi-0.37.2 examples/https_wss_server.rb
tipi-0.37.1 examples/https_wss_server.rb
tipi-0.37 examples/https_wss_server.rb
tipi-0.36 examples/https_wss_server.rb
tipi-0.35 examples/https_wss_server.rb
tipi-0.34 examples/https_wss_server.rb
tipi-0.33 examples/https_wss_server.rb
tipi-0.32 examples/https_wss_server.rb
tipi-0.31 examples/https_wss_server.rb
tipi-0.30 examples/https_wss_server.rb