2013-05-02 139 views
0

我有一個大問題。我無法從android模擬器連接到Java服務器套接字。我有日誌和代碼:無法連接到互聯網,連接拒絕

我使用的是2.1版本(埃克萊爾)模擬器來運行我的Android應用程序。

System.out.println("Sup"); 
try{ 
    Socket socket = new Socket("127.0.0.1", 26753); 
    PrintWriter out = new PrintWriter(socket.getOutputStream(), true); 
    out.println("e:ask"); 
    out.println("p:pass"); 
    out.println("EOF"); 
    socket.close(); 
} catch (Exception e){ 
    e.printStackTrace(); 
} 

logcat的錯誤:

05-02 21:35:41.986: I/System.out(276): Sup 
05-02 21:35:41.996: W/System.err(276): java.net.ConnectException: /127.0.0.1:26753 - Connection refused 
05-02 21:35:41.996: W/System.err(276): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:255) 
05-02 21:35:41.996: W/System.err(276): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:220) 
05-02 21:35:41.996: W/System.err(276): at java.net.Socket.startupSocket(Socket.java:780) 
05-02 21:35:41.996: W/System.err(276): at java.net.Socket.tryAllAddresses(Socket.java:192) 
05-02 21:35:42.006: W/System.err(276): at java.net.Socket.<init>(Socket.java:256) 
05-02 21:35:42.006: W/System.err(276): at java.net.Socket.<init>(Socket.java:220) 
05-02 21:35:42.006: W/System.err(276): at TestClass.skytheventure.TestClass.onClick(TestClass.java:38) 
05-02 21:35:42.006: W/System.err(276): at android.view.View.performClick(View.java:2364) 
05-02 21:35:42.006: W/System.err(276): at android.view.View.onTouchEvent(View.java:4179) 
05-02 21:35:42.006: W/System.err(276): at android.widget.TextView.onTouchEvent(TextView.java:6541) 
05-02 21:35:42.006: W/System.err(276): at android.view.View.dispatchTouchEvent(View.java:3709) 
05-02 21:35:42.006: W/System.err(276): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 
05-02 21:35:42.006: W/System.err(276): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 
05-02 21:35:42.006: W/System.err(276): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 
05-02 21:35:42.016: W/System.err(276): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 
05-02 21:35:42.016: W/System.err(276): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659) 
05-02 21:35:42.016: W/System.err(276): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107) 
05-02 21:35:42.016: W/System.err(276): at android.app.Activity.dispatchTouchEvent(Activity.java:2061) 
05-02 21:35:42.016: W/System.err(276): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643) 
05-02 21:35:42.016: W/System.err(276): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691) 
05-02 21:35:42.016: W/System.err(276): at android.os.Handler.dispatchMessage(Handler.java:99) 
05-02 21:35:42.016: W/System.err(276): at android.os.Looper.loop(Looper.java:123) 
05-02 21:35:42.016: W/System.err(276): at android.app.ActivityThread.main(ActivityThread.java:4363) 
05-02 21:35:42.016: W/System.err(276): at java.lang.reflect.Method.invokeNative(Native Method) 
05-02 21:35:42.027: W/System.err(276): at java.lang.reflect.Method.invoke(Method.java:521) 
05-02 21:35:42.027: W/System.err(276): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 
05-02 21:35:42.027: W/System.err(276): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
05-02 21:35:42.027: W/System.err(276): at dalvik.system.NativeStart.main(Native Method) 

我需要更多的權限?

回答

1

127.0.0.1是模擬器的IP。 10.0.2.2是你在找什麼(在模擬器上運行的主機)

+0

我現在就試試吧:) – KeirDavis 2013-05-03 06:20:52

0

首先,確保你把網上的權限在您的清單文件,並確保您的主機和端口號是正確的,並最後檢查你是否有權訪問該主機+端口。

+0

我在清單中的Android權限。一切都是正確的,它只是給'連接被拒絕' – KeirDavis 2013-05-03 06:21:34

+0

hımm嘗試另一個主機? – 2013-05-03 07:36:18

+0

現在修復。感謝WarrenFaith – KeirDavis 2013-05-03 17:14:07

相關問題