Sha256: aa21d30b801d2ca8a0b1c8350675d2862f6092a9a782331eda1b21551064b353

Contents?: true

Size: 469 Bytes

Versions: 6

Compression:

Stored size: 469 Bytes

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'polyphony/http'

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

opts = {
  reuse_addr:  true,
  dont_linger: true,
  upgrade:     {
    websocket: Polyphony::Websocket.handler(&method(:ws_handler))
  }
}

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

6 entries across 6 versions & 2 rubygems

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