Sha256: c577581989c6e59ab1084d69f993baade3468b4e40b4bbcc77ffa7637df31134

Contents?: true

Size: 819 Bytes

Versions: 15

Compression:

Stored size: 819 Bytes

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'tipi'
require 'tipi/websocket'
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: Tipi::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

15 entries across 15 versions & 1 rubygems

Version Path
tipi-0.55 examples/https_wss_server.rb
tipi-0.54 examples/https_wss_server.rb
tipi-0.53 examples/https_wss_server.rb
tipi-0.52 examples/https_wss_server.rb
tipi-0.51 examples/https_wss_server.rb
tipi-0.50 examples/https_wss_server.rb
tipi-0.49 examples/https_wss_server.rb
tipi-0.47 examples/https_wss_server.rb
tipi-0.46 examples/https_wss_server.rb
tipi-0.45 examples/https_wss_server.rb
tipi-0.43 examples/https_wss_server.rb
tipi-0.42 examples/https_wss_server.rb
tipi-0.41 examples/https_wss_server.rb
tipi-0.40 examples/https_wss_server.rb
tipi-0.39 examples/https_wss_server.rb