Sha256: 3aa5a2670efc4f8ac45c67bfa42a5130d1d879304dad987af9e2db36bf7bdc6a

Contents?: true

Size: 594 Bytes

Versions: 3

Compression:

Stored size: 594 Bytes

Contents

# frozen_string_literal: true

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

STDOUT.sync = true

def ws_handler(conn)
  while msg = conn.recv
    conn << "you said: #{msg}"
  end
end

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

puts "pid: #{Process.pid}"
puts "Listening on port 1234..."
Polyphony::HTTP::Server.serve('0.0.0.0', 1234, opts) do |req|
  req.respond("Hello world!\n")
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
polyphony-0.19 examples/http/websocket_secure_server.rb
polyphony-0.17 examples/http/websocket_secure_server.rb
polyphony-0.16 examples/http/websocket_secure_server.rb