Sha256: fb7cdab0e471dc3ecc051308f492a1dfd11b95c0cef85365921b17b5048a81f9

Contents?: true

Size: 801 Bytes

Versions: 1

Compression:

Stored size: 801 Bytes

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'polyphony/http'
require 'localhost/authority'

STDOUT.sync = true

def ws_handler(conn)
  timer = spin {
    throttled_loop(1) {
      conn << Time.now.to_s rescue nil
    }
  }
  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

1 entries across 1 versions & 1 rubygems

Version Path
polyphony-0.19 examples/http/https_wss_server.rb