hii i am suffering from Error on connection: java.net.ConnectException: /127.0.0.1:9898 - Connection refused in android

328 views
Skip to first unread message

pintu patil

unread,
May 2, 2015, 9:55:25 AM5/2/15
to uni...@googlegroups.com
From console it's working as

 curl http://127.0.0.1:9898/addpsp -d service=pkpservice -d pushservicetype=gcm -d projectid=172993292454 -d apikey=AIzaSyDPuuxs_c4paDQcmWabiGmmaViXOrIC5d0

[AddPushServiceProvider][Info] 2015/05/02 19:21:58 From=127.0.0.1:41535 Service=pkpservice PushServiceProvider=gcm:8b3cf1f54e6baa5ac338708d778f111b95344bcc Success!

 
but in android it's always through Error on connection: java.net.ConnectException: /127.0.0.1:9898 - Connection refused in android

My source code is :

BigInteger modulus = new BigInteger(
                "17388413383649711290254825310339272211319767525363227404074762677568514182143042061437868796167591657550511002079944736281939887225873458139996723826487428401781326377898963252196351565707602724215593767581359596805150972910866410145077679809190513515791700412131297152963158161216863933118912237764396054712362877219981113432778260759907285938711897115187091296093563327334234754294283390985106557355671509013541665508032935881514071942658154269549566084778139622274561728679270315969220599430415442568612476273211334694395646067337896362196452349792104972786584396268761019495750809374141828098785614861562903854521");
        BigInteger exp = new BigInteger("65537");
        KeySpec keyspec = new RSAPublicKeySpec(modulus, exp);
        KeyFactory kf = null;
        try {
            kf = KeyFactory.getInstance("RSA");
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        pubKey = null;
        try {
            pubKey = (RSAPublicKey) kf.generatePublic(keyspec);
        } catch (InvalidKeySpecException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        this.cinfo = new ConnectionInfo("127.0.0.1", 9898, "pkpservice", "pkp");
        this.cinfo2 = new ConnectionInfo("127.0.0.1", 9898, "pkpservice",
                "monnand", true, false, 1024, 1024);
     
    }

    @Override
    public String getToken(String service, String username) {
        return "token/password";
    }

    @Override
    public RSAPublicKey getPublicKey(String addr, int port) {
        return this.pubKey;
    }

    @Override
    public String[] getSenderIds() {
        String[] senderIds = new String[1];
        senderIds[0] = "172993292454";
        return senderIds;
    }

    @Override
    public MessageHandler getMessageHandler(String service, String username) {
        return new MessageEcho(this.context);
    }

    @Override
    public ConnectionInfo getConnectionInfo() {
        if (Math.random() > 0.5) {
            Log.i(TAG, "Use the second config");
            return cinfo2;
        }
        Log.i(TAG, "Use the first config");
        return cinfo;
    }

i dont know BigInteger value

Misha Nasledov

unread,
Jun 2, 2015, 6:26:08 PM6/2/15
to uni...@googlegroups.com
On Saturday, May 2, 2015 at 6:55:25 AM UTC-7, pintu patil wrote:
From console it's working as

 curl http://127.0.0.1:9898/addpsp -d service=pkpservice -d pushservicetype=gcm -d projectid=172993292454 -d apikey=AIzaSyDPuuxs_c4paDQcmWabiGmmaViXOrIC5d0

[AddPushServiceProvider][Info] 2015/05/02 19:21:58 From=127.0.0.1:41535 Service=pkpservice PushServiceProvider=gcm:8b3cf1f54e6baa5ac338708d778f111b95344bcc Success!\

This works because you are presumably running uniqush-push on the same host as you are making the curl request from. 127.0.0.1 is the IP address for "localhost" -- it points to the machine making the request.

 
but in android it's always through Error on connection: java.net.ConnectException: /127.0.0.1:9898 - Connection refused in android

        this.cinfo = new ConnectionInfo("127.0.0.1", 9898, "pkpservice", "pkp");
        this.cinfo2 = new ConnectionInfo("127.0.0.1", 9898, "pkpservice",

The problem is you're trying to connect to 127.0.0.1. On the Android, 127.0.0.1 will be the mobile device itself, which is not running uniqush-push. Presumably the server your running uniqush-push on has a public IP here to use instead?

Some words of caution regarding exposing uniqush-push for clients to call directly -- if someone discovers your service they can kill it via /stop or do other very nasty things. I've been developing a tier that uses uniqush-push at my company and I only have the backend code talk to it. It is a firewalled-off, internal service here.

Misha Nasledov

unread,
Jun 2, 2015, 6:27:15 PM6/2/15
to uni...@googlegroups.com
For more information on localhost AKA 127.0.0.1 (for IPv4) or ::1 for IPv6, please see the Wikipedia article on the subject. http://en.wikipedia.org/wiki/Localhost
Reply all
Reply to author
Forward
0 new messages