Ruby:解压缩Websocket响应

时间:2016-01-15 15:26:58

标签: ruby websocket compression

我正在寻找一种解压缩websocket响应的方法,以便我可以阅读它。我尝试过zlib,但是我收到了数据错误:

#<Zlib::DataError: incorrect header check>
#<Zlib::DataError: unknown compression method>

这就是我所拥有的:

require 'websocket-client-simple'
require 'zlib'

WSURL = 'wss://real.okcoin.com:10440/websocket/okcoinapi'

def inflate(deflated_string)
  inflater = Zlib::Inflate.new(Zlib::MAX_WBITS + 32)
  inflater.inflate(deflated_string)
end

ws = WebSocket::Client::Simple.connect WSURL

ws.on :message do |msg|
  puts inflate(msg.data)
end

ws.on :open do
  puts "connection opened"
  ws.send "{'event':'addChannel','channel':'ok_btcusd_ticker','binary':'true'}"
  puts "addChannel sent"
end

ws.on :close do |e|
  p e
  exit 1
end

ws.on :error do |e|
  p e
end

loop do
  sleep 1
end

我不知道它可能是什么?

0 个答案:

没有答案