簡體   English   中英

android應用程序連接到jboss服務器時,拒絕連接

[英]getting connection refused while connection android app to jboss server

我正在嘗試測試通過Web Service連接到jboss服務器的Android應用程序 當我使用127.0.0.1或我的內部IP(具有Internet訪問權限)時,該程序運行良好。 但是,每當我切換到沒有Internet訪問權限的網絡(例如addhoc)時,都會拋出
java.net.ConnectException: Connection refused: connect error.

但是我可以通過在瀏覽器中鍵入IP address:port來訪問服務器。

如果我要ping服務器IP地址,則ping將會成功。

我關閉了防火牆,但結果始終相同。

關於該怎么辦的任何想法? 謝謝

它似乎不是ipaddress的JBoss參數(默認情況下處於關閉狀態)。

但是,如果您想使用Android設備調用該服務,則需要互聯網才能使用該服務。 或需要確保Android設備獲得本地ip ...然后通過192.xxx而不是127.0.0.1進行調用...

最好是檢查路由器/防火牆,以便將外部ip:port移植到您的開發計算機上...然后讓Android(使用Internet)調用外部ipaddress ...

這是將登錄名和密碼發送到服務器的提交代碼

try {
    json.put("utCode", ((EditText) findViewById(R.id.et_login)).getText());
    json.put("utPassword", ((EditText) findViewById(R.id.et_pass)).getText());
    new PostLogin().execute(Settings.getServerAddress(getBaseContext()) + "/auth/login", json);

} catch (JSONException e) {
    Log.e("log_tag", "Error parsing data " + e.toString());
}


private class PostLogin extends AsyncTask<Object, Integer, String> {
    private ProgressDialog Dialog = new ProgressDialog(MainActivity.this);

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        Dialog.setMessage("Please wait..");
        Dialog.show();
    }

    @Override
    protected String doInBackground(Object... params) {
        String url = (String) params[0];
        JSONObject json = (JSONObject) params[1];

        // Dummy code
        InputStream is = null;
        HttpResponse response = null;  
        try {
            response = RestEasy.doPost(url, json);
            if (response.getStatusLine().getStatusCode() == 500) {
                return "500";
            } else if (response.getStatusLine().getStatusCode() == 404) {
                return "404";
            }

            HttpEntity entity = response.getEntity();
            if (entity != null) {

                is = entity.getContent();

                String result = "";
                result = RestEasy.convertStreamToString(is);
                return result;
            } else {
                return "null";
            }
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
}

當我使用可以訪問互聯網的網絡時,代碼可以正常運行,但是如果我使用不可以訪問互聯網的網絡,則會拋出一個錯誤

java.net.ConnectException: Connection refused: connect error.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM