I need to sent 500 push notifications per second across gcm service. Unfortunately unlike chrome49 I have to encrypt message for every chrome50 customer, encryption keys are indicated in the request header. After above 5000 messages sent i receive Timeout & Connection Refused from https://android.googleapis.com/gcm/send and its stop working for some time and then works normally periodically
Post requests runing in threads
try {
String path = "https://android.googleapis.com/gcm/send";
URI uri = new URIBuilder()
.setPath(path)
.build();
HttpPost httpPost = new HttpPost(uri);
httpPost.addHeader("Accept", "application/json");
httpPost.addHeader("Content-Encoding", "aesgcm");
httpPost.addHeader("Cache-Control", "no-cache");
httpPost.addHeader("Connection", "Keep-Alive");
httpPost.addHeader("Content-Type", "application/json");
httpPost.addHeader("Authorization", "key=" + appKey);
httpPost.addHeader("Encryption", encryptionHeader);
httpPost.addHeader("Crypto-Key", cryptoKeyHeader);
httpPost.setEntity(new StringEntity(jsonFromData));
HttpResponse response = client.execute(httpPost);
HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity).replace("%", "@");
LOGGER.info(responseString);
} catch (Exception e) {
e.printStackTrace();
}
Exception: connection refused
org.apache.http.conn.HttpHostConnectException: Connection to https://android.googleapis.com refused at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:190) at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294) at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:643) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784) at com.mpsdevelopment.push.threads.SenderThread.sent(SenderThread.java:100) at com.mpsdevelopment.push.threads.SenderThread.run(SenderThread.java:76) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)
Connection timed out
Caused by: java.net.ConnectException: Connection timed out: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668) at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:414) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180) ... 13 more
When you experience ERR_CONNECTION_REFUSED
, check your internet connection, check any cables and reboot any routers, modems, or other network devices you may be using. The error mainly occurs due to the problems in the internet connection and if there are problems in the devices you use to connect to the internet. Follow the steps in this link to solve this problem.
Based from this thread, many problems can crop up in corporate networks, since firewalls might block access to the rather unusual port or proxies might interfere with any outgoing traffic. The exception indicates a networking problem on your part – it’s simply getting a timeout. I guess neither Google nor your provider are the problem here. Check your setup and any firewalls (corporate or personal) between you and the outer internet.