Sha256: 7f1c3b1154de8c80470ad73e35da54429a8ed3d0fc8c3d1e53e67114ddde46b6

Contents?: true

Size: 828 Bytes

Versions: 6

Compression:

Stored size: 828 Bytes

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'polyphony/http'
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...'
Polyphony::HTTP::Server.serve('0.0.0.0', 1234, opts) do |req|
  req.respond(HTML, 'Content-Type' => 'text/html')
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
polyphony-http-0.28 examples/https_wss_server.rb
polyphony-http-0.27 examples/https_wss_server.rb
polyphony-http-0.26 examples/https_wss_server.rb
polyphony-http-0.25 examples/https_wss_server.rb
polyphony-http-0.24 examples/https_wss_server.rb
polyphony-0.23 examples/http/https_wss_server.rb