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串
我能做些什么来阅读正确的信息?