自述文件有以下faye-websocket-ruby
示例。代码行是什么
p [:close, event.code, event.reason]
do 是什么p
意思?还有什么ws.rack_response
做,为什么有必要?
# app.rb
require 'faye/websocket'
App = lambda do |env|
if Faye::WebSocket.websocket?(env)
ws = Faye::WebSocket.new(env)
ws.on :message do |event|
ws.send(event.data)
end
ws.on :close do |event|
p [:close, event.code, event.reason]
ws = nil
end
# Return async Rack response
ws.rack_response
else
# Normal HTTP request
[200, {'Content-Type' => 'text/plain'}, ['Hello']]
end
end