Android应用程序-套接字异常:操作超时
我正在编写一个 Android 客户端,它通过网络服务使用来自服务的一些数据。在模拟器上运行应用程序时,一切都很好。现在我想在真实设备上测试我的应用程序。服务器目前正在本地运行。登录失败。
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();
}
以前有人遇到过这个问题或者可能有一些想法吗?
问候 克里斯汀
i´m writing an android client, which uses some data from a service via webservices. while running the app on the emulator, everything is fine. now i would like to test my app on a real device. the server is running local at the moment. the loggin fails.
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)
here is my login:
// 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();
}
did anyone had this problem before or might have some ideas?
greetings
christine
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能否确认您的设备网络无线电已打开并且可以通过 Wi-Fi 或 GSM 无线电连接到您的服务器?
Can you please confirm that your devices network radios are on and have reachability to your server via Wi-Fi or GSM radio?