12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/websocket/echo/io/server.rb', line 12
def start
handler = Handler.new
app = proc do |env|
if env["rack.upgrade?"] == :websocket
env["rack.upgrade"] = handler
[0, {}, []] elsif env["rack.upgrade?"] == :sse
puts "SSE connections can only receive data from the server, they can't write."
env["rack.upgrade"] = handler
[0, {}, []] else
body = "Upgrade connection to Websocket to enter echo mode."
[405, { "Content-Length" => body.bytesize, "Content-Type" => "text/plain" }, [body]]
end
end
Iodine.listen service: :ws, address: "::", port: PORT, handler: app
Iodine.start
end
|