0
我在我的應用程序中創建一個帶有服務器的套接字並從服務器讀取輸出的自定義類。問題是輸出不正確。因爲我看到輸出是在ssl密碼術下進行的,而當我讀它時,它是錯誤的。通過SSL ruby讀取服務器響應
這是從巫婆我創建SSL連接的方法
def self.feedback_connection
raise "The path to your pem file is not set. (APNS.pem = /path/to/cert.pem)" unless self.pem
raise "The path to your pem file does not exist!" unless File.exist?(self.pem)
context = OpenSSL::SSL::SSLContext.new
context.cert = OpenSSL::X509::Certificate.new(File.read(self.pem))
context.key = OpenSSL::PKey::RSA.new(File.read(self.pem), self.pass)
fhost = self.host.gsub('gateway','feedback')
puts fhost
sock = TCPSocket.new(fhost, 2196)
sock.setsockopt Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true
ssl = OpenSSL::SSL::SSLSocket.new(sock,context)
ssl.sync = true
ssl.connect
return sock, ssl
end
然後,在我的主要metodh
def self.feedback
sock, ssl = self.feedback_connection
apns_feedback = []
while line = sock.gets # Read lines from the socket << the problem is here
line.strip!
f = line.unpack('N1n1H140')
apns_feedback << [Time.at(f[0]), f[2]]
end
ssl.close
sock.close
return apns_feedback
end
在該行
:while line = sock.gets
如果我使用sock.gets
我得到的編纂字符串。如果我使用ssl.read(38)
這將返回null。
我需要時間來閱讀38個字節,在這個配置:
1..4 => timestamp (big endian)
5..6 => length (big endian)
7..38 => token (binary) quoting: The token in binary format.
所以我的問題是:使用SSL我不能閱讀所有與插座每次我得到一個diferent串
我能做些什麼來閱讀正確的信息?