Method: WebSocket#close
- Defined in:
- lib/web/web-socket-ruby/lib/web_socket.rb
#close(code = 1005, reason = "", origin = :self) ⇒ Object
Does closing handshake.
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/web/web-socket-ruby/lib/web_socket.rb', line 275 def close(code = 1005, reason = "", origin = :self) if !@closing_started case @web_socket_version when "hixie-75", "hixie-76" write("\xff\x00") else if code == 1005 payload = "" else payload = [code].pack("n") + force_encoding(reason.dup(), "ASCII-8BIT") end send_frame(OPCODE_CLOSE, payload, false) end end @socket.close() if origin == :peer @closing_started = true end |