Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCM push notifications not coming through proxy

I'm developing a small app for my course project (similar to Snapchat) that allows one to send and receive pictures and videos. I'm using a BaaS called Parse which uses GCM to deliver push notifications. However, the problem is that my campus uses a proxy network due to which numerous apps do not work (WhatsApp, Instagram) while some apps (Snapchat) work but their notifications are not delivered. Same is the case with my app.

Is there any possible way to overcome this problem assuming I do not have any influence over the proxy network and cellular network is out of options.

enter image description here

like image 629
Rafay Avatar asked Feb 11 '23 07:02

Rafay


2 Answers

It all depends on your campus network access policy. You cant do if your campus proxy firewall doesnt provide access to these sites. However, you can ask them to allow these URL through their proxy firewall.

Or, simply you can use some other external proxy server by adding lines in your code

System.setProperty("https.proxyHost", "<IP>"); System.setProperty("https.proxyPort", "<Port>");

where you are trying to connect the Google APIs. Say if you are using something like this,

URL url = new URL("https://android.googleapis.com/gcm/send");
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", "key="+<your api key>);

Before these lines where you attempting to connect to Google API, add the proxy setting lines, the above two lines. Also, try with your campus proxy as well some other external proxy, you will come to know issue is with your campus proxy or not.

Try this, hope this helps with your problem..!!!!!

like image 64
ajitksharma Avatar answered Feb 13 '23 21:02

ajitksharma


Use Something like this,

import com.google.android.gcm.server.Sender;

public class ProxySender extends Sender {

public ProxySender(String key) {
    super(key);
    // TODO Auto-generated constructor stub
}

@Override
protected HttpURLConnection getConnection(String url) throws IOException {

    Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("<YOUR SERVER IP>", YOUR PORT));

    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(proxy);

    return conn;

}
}
like image 45
Hardik Chauhan Avatar answered Feb 13 '23 20:02

Hardik Chauhan