Android App - 套接字异常:操作超时

时间:2011-03-02 10:24:28

标签: android socketexception

我正在编写一个Android客户端,它通过webservices使用服务中的一些数据。在模拟器上运行应用程序时,一切都很好。现在我想在真实设备上测试我的应用程序。服务器此刻正在本地运行。登录失败。

03-02 10:27:31.066: WARN/System.err(6301): java.net.SocketException: The operation timed out
03-02 10:27:31.077: WARN/System.err(6301):     at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocketImpl(Native Method)
03-02 10:27:31.077: WARN/System.err(6301):     at org.apache.harmony.luni.platform.OSNetworkSystem.connect(OSNetworkSystem.java:115)
03-02 10:27:31.077: WARN/System.err(6301):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:244)
03-02 10:27:31.077: WARN/System.err(6301):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:533)
03-02 10:27:31.077: WARN/System.err(6301):     at java.net.Socket.connect(Socket.java:1055)
03-02 10:27:31.077: WARN/System.err(6301):     at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
03-02 10:27:31.077: WARN/System.err(6301):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
03-02 10:27:31.077: WARN/System.err(6301):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
03-02 10:27:31.087: WARN/System.err(6301):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
03-02 10:27:31.087: WARN/System.err(6301):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
03-02 10:27:31.087: WARN/System.err(6301):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
03-02 10:27:31.087: WARN/System.err(6301):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:653)
03-02 10:27:31.087: WARN/System.err(6301):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627)
03-02 10:27:31.087: WARN/System.err(6301):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616)
03-02 10:27:31.087: WARN/System.err(6301):     at com.mobilesociato.activities.Login.onLogin(Login.java:121)
03-02 10:27:31.087: WARN/System.err(6301):     at java.lang.reflect.Method.invokeNative(Native Method)
03-02 10:27:31.087: WARN/System.err(6301):     at java.lang.reflect.Method.invoke(Method.java:521)
03-02 10:27:31.087: WARN/System.err(6301):     at android.view.View$1.onClick(View.java:2067)
03-02 10:27:31.087: WARN/System.err(6301):     at android.view.View.performClick(View.java:2408)
03-02 10:27:31.087: WARN/System.err(6301):     at android.view.View$PerformClick.run(View.java:8817)
03-02 10:27:31.087: WARN/System.err(6301):     at android.os.Handler.handleCallback(Handler.java:587)
03-02 10:27:31.097: WARN/System.err(6301):     at android.os.Handler.dispatchMessage(Handler.java:92)
03-02 10:27:31.097: WARN/System.err(6301):     at android.os.Looper.loop(Looper.java:144)
03-02 10:27:31.097: WARN/System.err(6301):     at android.app.ActivityThread.main(ActivityThread.java:4937)
03-02 10:27:31.097: WARN/System.err(6301):     at java.lang.reflect.Method.invokeNative(Native Method)
03-02 10:27:31.097: WARN/System.err(6301):     at java.lang.reflect.Method.invoke(Method.java:521)
03-02 10:27:31.097: WARN/System.err(6301):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-02 10:27:31.097: WARN/System.err(6301):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-02 10:27:31.097: WARN/System.err(6301):     at dalvik.system.NativeStart.main(Native Method)

这是我的登录信息:

// Anfrage Login
    HttpPost requestLogin = new HttpPost(PathContainer.loginURL);
    HttpResponse response = null;

    // Parameter fuer Post Anfrage an die URL spring_security_check
    // Name und Password werden uebergeben
    // Login wie in Browser
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("j_username", username));
    params.add(new BasicNameValuePair("j_password", password));

    // LOGIN
    // Fuegt Parameter (Name und Password) der URL hinzu
    try {
        requestLogin
                .setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    HttpHost proxy = new HttpHost("192.168.1.116", 8080);
    c.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

    try {
        response = c.execute(requestLogin);
    } catch (ClientProtocolException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

之前有没有人遇到过这个问题,或者可能有一些想法?

问候 恭

1 个答案:

答案 0 :(得分:0)

您能否确认您的设备网络无线电已打开,并且可通过Wi-Fi或GSM无线电与您的服务器连接?