Apple推APNS连接

时间:2011-08-01 19:02:40

标签: java ios ssl

我正在尝试连接到Apple的推送通知服务器以发送通知,但我遇到了一些连接问题。在我尝试握手之后,它显示说我没有连接。我没有任何例外?这不是我的证书的问题,因为我尝试使用带有证书的第三方库,我能够毫无问题地推送。

int port = 2195;
String hostname = "gateway.sandbox.push.apple.com";
char[] passwKey = "password".toCharArray();

KeyStore ts = KeyStore.getInstance("PKCS12");
ts.load(new FileInputStream("/path/to/file/Cert.p12"), passwKey);
KeyManagerFactory tmf = KeyManagerFactory.getInstance("SunX509");
tmf.init(ts, passwKey);

SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(tmf.getKeyManagers(), null, null);
SSLSocketFactory factory = sslContext.getSocketFactory();

SSLSocket socket = (SSLSocket) factory.createSocket(hostname,port); 
String[] suites = socket.getSupportedCipherSuites();
socket.setEnabledCipherSuites(suites);
//start handshake
socket.startHandshake();

//THIS ALWAYS RETURNS FALSE
boolean connected = socket.isConnected();

1 个答案:

答案 0 :(得分:0)

这总是返回false,但我能够毫无问题地进行通信。 boolean connected = socket.isConnected();