我有一個大問題。我無法從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)
我需要更多的權限?
我現在就試試吧:) – KeirDavis 2013-05-03 06:20:52