0

First of all I will tell you what can I do:

  • I can connect my real device to my servlets on my website using my computer IP

  • I can connect my emulator to my servlets on my website using 10.0.2.2 IP

  • I can connect my emulator to my web services using 10.0.2.2 IP

My problem.

I can't connect my real device to the web services;

I tried this (It works for emulator);

public class Client {

    private String server;

    public Client(String server) {
        this.server = server;
    }

    private String getBase() {
        return server;
    }

    public String getBaseURI(String str) {
        String result = "";
        try {
            HttpParams httpParameters = new BasicHttpParams();
            int timeoutConnection = 3000;
            HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
            int timeoutSocket = 5000;
            HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
            DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
            HttpGet getRequest = new HttpGet(getBase() + str);
            getRequest.addHeader("accept", "application/json");
            HttpResponse response = httpClient.execute(getRequest);
            result = getResult(response).toString();
            httpClient.getConnectionManager().shutdown();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } 
        return result;
    }

    public String getBaseURIText(String str) {
        String result = "";
        try {
            HttpParams httpParameters = new BasicHttpParams();
            int timeoutConnection = 3000;
            HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
            int timeoutSocket = 5000;
            HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
            DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
            HttpGet getRequest = new HttpGet(getBase() + str);
            getRequest.addHeader("accept", "text/plain");
            HttpResponse response = httpClient.execute(getRequest);
            result = getResult(response).toString();
            httpClient.getConnectionManager().shutdown();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return result;
    }

 private StringBuilder getResult(HttpResponse response) throws IllegalStateException, IOException {
            StringBuilder result = new StringBuilder();
            BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())), 1024);
            String output;
            while ((output = br.readLine()) != null) 
                result.append(output);

            return result;      
      }
}

Then I call that client like this:

Client client = new Client("http://46.57.164.64:8080/test2/eattel/");
            client.getBaseURI("image/image");

This totally works for emulators. but now for my real device :(

I connect my real device to my computer using cable .

my computer and my device are connected to connectify-me wireless network.

please help

I am sure it is something about IP

4

2 回答 2

2

我认为这里出了问题是您通过电缆连接您的计算机和您的真实设备。您的真实设备应通过 WiFi 连接到无线网络。您的计算机还应通过电缆或 WiFi 连接到无线网络。然后,一旦您在 Real Device 的 Internet 浏览器上键入您的计算机 IP 地址,您应该能够看到您在计算机上运行的服务器的主页。如果出现这种情况,您的应用程序可以与计算机中的 Web 服务进行通信。如果这没有出现,则意味着您的 IP 地址未正确设置无线网络。您可能需要重新启动无线网络并重试。

于 2013-05-30T12:22:24.787 回答
0

您是否尝试发现您的计算机 IP 地址以进行连接连接?如果您使用的是 Windows 操作系统,请转到命令提示符,键入 ipconfig 并在无线 LAN 适配器本地连接下搜索 ipv4 地址。如果使用 connectify,它通常以 192.168.xxx.xxx 开头

于 2013-05-30T09:21:56.030 回答