-1

我正在尝试通过 http 将 android 手机连接到在我的本地计算机上运行的服务器并输出内容但不成功..!

这是我的代码:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try {

        URL url = new URL("http://192.168.24.42:80/DebugServer/");
        HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();     
        InputStream in = new BufferedInputStream(urlConnection.getInputStream());
        readStream(in);
        urlConnection.disconnect();

    } catch (IOException e) {
        e.printStackTrace();
}


private void readStream(InputStream in) {

    try {
        in.read();
        in.read();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
4

1 回答 1

0
URL url = new URL("http://192.168.24.42:80/DebugServer/");  

是您的连接 URL。将端口更改为,8080因为这是服务器侦听的位置。

另外,您是否转到您的bin文件夹tomcat(我假设在这里)并运行startup.BATorstartup.SH文件,因为没有它,您的服务器就没有运行。

要检查您的服务器是否正常运行,http://localhost:8080
请尝试发布 logcat :)

于 2013-08-27T17:23:11.237 回答