简体   繁体   English

Java / Android-获取套接字输出流会中断执行,且不会启动任何异常

[英]Java/Android - Getting socket output stream breaks execution with no exception launched

I'm debugging the thread which manages a socket and I noticed that when I call getOutputStream() the debug breaks with no exception thrown. 我正在调试管理套接字的线程,并且注意到当我调用getOutputStream()时,调试会中断,并且不会引发任何异常。 I've even added breakpoints to the very Socket.getOutputStream() but there is no way to get what's wrong. 我什至在Socket.getOutputStream()中添加了断点,但是没有办法解决问题。 The Java server correctly accepts the connection and waits for input (by checking inputStream.available()). Java服务器正确接受连接并等待输入(通过检查inputStream.available())。 Both Socket and ServerSocket come from SSLSocketFactory and SSLServerSocketFactory. Socket和ServerSocket都来自SSLSocketFactory和SSLServerSocketFactory。

I'm using Android Studio. 我正在使用Android Studio。

What am I doing wrong? 我究竟做错了什么?

edit: I've even tried to change structure from Thread to AsyncTask but the result is the same. 编辑:我什至试图将结构从Thread更改为AsyncTask,但结果是相同的。 This is frustrating. 这真令人沮丧。

Debugging network connections is a bit tricky as time-outs may occur. 调试网络连接有点棘手,因为可能会发生超时。

I am also unsure if breakpoints on non-app-code (like Socket.getOutputStream() ) will really work. 我也不确定非应用程序代码(例如Socket.getOutputStream() )上的断点是否真的起作用。 The SDK code in AndroidStudio may be different to the one used by your devices which mean that breakpoints (which are set to a specific line) may end up in a totally different method (if they work at all). AndroidStudio中的SDK代码可能与您的设备所使用的SDK代码不同,这意味着断点(设置为特定行)可能会以完全不同的方法结束(如果它们完全起作用)。

Therefore I would suggest to change your code and add log statements and if necessary sleep commands to slow-down the important parts. 因此,我建议您更改代码并添加日志语句,并在必要时添加sleep命令以减慢重要部分的速度。

For SSL traffic I strongly suggest to look also at the transferred data. 对于SSL流量,我强烈建议您也查看传输的数据。 There are apps capturing the traffic on-device that run without root permissions. 有一些应用程序捕获设备上的流量,这些应用程序在没有root权限的情况下运行。 Later you can then debug the traffic on the PC using Wireshark and see if the problem was caused by a communication problem between your client and the server. 稍后,您可以使用Wireshark在PC上调试流量,并查看问题是否是由客户端和服务器之间的通信问题引起的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM