"没有路由到主机"关于设备的getOutputStream() - 无线连接 [英] "no route to host" on device on getOutputStream() - connected wirelessly
问题描述
private String urlPost = "http://192.168.1.66:8080/DataCollectionServlet/";
@Override
protected void doWakefulWork(Intent intent) {
// http://stackoverflow.com/q/14630255/281545
HttpURLConnection connection = null;
try {
connection = connection();
w("connection"); // allrigt
final OutputStream connOutStream = connection.getOutputStream();
w("GEToUTPUTsTREAM"); // I never see this
} catch (IOException e) {
e.printStackTrace(); // No route to host
} finally {
if (connection != null) connection.disconnect();
}
}
private HttpURLConnection connection() throws MalformedURLException,
IOException {
HttpURLConnection connection = (HttpURLConnection) new URL(urlPost)
.openConnection();
// connection.setDoInput(true);
connection.setDoOutput(true); // triggers POST
// connection.setUseCaches(false); // needed ?
// TODO : http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
// connection.setRequestProperty("Connection", "Keep-Alive");
// connection.setRequestProperty("User-Agent",
// "Android Multipart HTTP Client 1.1"); // needed ?
return connection;
}
在 192.168.1.66:8080/DataCollectionServlet /
服务器启动并运行。我的设备的IP 是 192.168.1.65
。我禁用这两个窗口和路由器的防火墙也没有用。
The server in 192.168.1.66:8080/DataCollectionServlet/
is up and running. My device IP is 192.168.1.65
. I disabled both window's and the router's firewall to no avail.
编辑 - 堆栈跟踪:
java.net.SocketException: No route to host
at org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method)
at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:357)
at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:204)
at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:437)
at java.net.Socket.connect(Socket.java:983)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:614)
at gr.uoa.di.monitoring.android.services.NetworkService.doWakefulWork(NetworkService.java:51)
at com.commonsware.cwac.wakeful.WakefulIntentService.onHandleIntent(WakefulIntentService.java:94)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.os.HandlerThread.run(HandlerThread.java:60)
点评:同样,在手机和PC都连接到同一个无线路由器(相同的SSID)
Comments : Again, the phone and PC are both connected to the same router wirelessly (same SSID)
安卓2.3.7埃克莱尔,HTC的Nexus 1 - ?可能这是一个错误
Android 2.3.7 Eclair, HTC Nexus 1 - could it be a bug ?
编辑二〇一三年十一月一十三日:在我
EDIT 2013.11.13 : still interested in ana explanation of my answer
推荐答案
好吧好吧 - 禁用( WPA-PSK
)我连正常的路由器加密。我会接受的答案一(编程)解决
Well well - disabling the (WPA-PSK
) Encryption on the router I connect alright. I would accept as an answer a (programmatic) work around
编辑:输入网址到Android设备的浏览器我看到的doGet()
页。我重新启用所有的防火墙 - 有差别的开启和关闭
EDIT : entering the URL into the android device's browser I do see the doGet()
page. I reenabled all firewalls - the only thing that makes a difference is toggling encryption on and off
这篇关于&QUOT;没有路由到主机&QUOT;关于设备的getOutputStream() - 无线连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!