0

I am looking for a way to decompress a websocket response so that I can read it. I have tried zlib, but I am getting Data Errors:

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

Here is what I have:

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

I do not exactly know what it could be?

Pabi
  • 946
  • 3
  • 16
  • 47
  • 1
    Here is a related question: http://stackoverflow.com/questions/1361892/how-to-decompress-gzip-string-in-ruby I'm not certain the solution to your problem is there, but there are several possibilities in the answers that are worth a shot. – Jordan Running Jan 15 '16 at 15:50
  • Thank you. The third solution: Zlib::Inflate.new(-Zlib::MAX_WBITS) worked for me. – Pabi Jan 15 '16 at 18:10

0 Answers0