2013-09-01 78 views
0
private String urlPost = "http://192.168.1.66:8080/DataCollectionServlet/"; 

@Override 
protected void doWakefulWork(Intent intent) { 
    // https://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/中的服務器已啓動並正在運行。我的device IP192.168.1.65。我禁用了窗口和路由器的防火牆都無濟於事。getOutputStream()上的設備上的「no host to host」(無線連接) - 無線連接

編輯 - 堆棧跟蹤:

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)

的Android 2.3.7埃克萊爾,HTC的Nexus 1 - 它可能是一個錯誤?

編輯2013年11月13日:在my answer

+0

看起來好像您的設備不在您的本地網絡中,而是在單獨的網絡上(公共或其他方式分開)。你有WLAN嗎?它是否連接到本地網絡的WLAN? – Codo

+0

@Codo:電腦是'192.168.1.66'而電話'192.168.1.65' - 他們都連接到相同的路由器無線,是(相同的SSID) –

+0

您是否嘗試輸入URL到Android設備的瀏覽器? – Merlin

回答

0

ANA解釋仍然有興趣好吧好吧 - 禁用我好嗎連接在路由器上(WPA-PSK)加密。我會接受作爲答案(編程)圍繞

編輯:輸入到Android設備的瀏覽器的URL我看到doGet()頁面。我重新啓用了所有的防火牆 - 唯一有所作爲的是打開和關閉加密

+0

@Codo:有什麼想法? –

相關問題