使用 telnet 时连接被外部主机关闭

Connection closed by foreign host while using telnet

我是第一次开发推送通知,遇到了这个 telnet 命令:

telnet gateway.push.apple.com 2195

我使用此命令得到以下响应

Trying 17.172.233.151...
Connected to gateway.push-apple.com.akadns.net.
Escape character is '^]'

但是大约 30 秒后,它显示为 "Connection closed by foreign host" 所以我很困惑我的服务器是否连接到 Apple Push Notification Server!

任何帮助将不胜感激,谢谢!

看到这个tutorial。获得必要的证书后,使用它来测试是否可以成功连接到 apns:

openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert PushChatCert.pem -key PushChatKey.pem

注意:如果遇到类似error:num=20:unable to get local issuer certificate的错误,只需下载entrust_2048_ca.cer,并与其他证书一起检查即可像这样:

openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert PushChatCert.pem -key PushChatKey.pem -CAfile entrust_2048_ca.cer