java BufferedReader works on windows and not mac

对着背影说爱祢 提交于 2019-12-05 18:59:46
Domi

You don't know what the server is sending and yet you are using a string reader that tries to read line by line. Note that a "line" is defined differently on different systems. In Windows, a line is terminated by "\r\n", and on MacOS it is terminated by either "\r" or "\n", depending on the version. Try reading byte by byte, and identify the packet terminator first.

Also, as explained here, just relying on ready() is not enough. It will return true if data is available (but that data might not be terminated by above mentioned line terminator, so readLine() would still block). If ready() returns false, it does not mean that the server is done sending data.

If that still does not help you, external network tools, such as Wireshark are invaluable for debugging network code. If you really think that there is a bug, make sure you have system-independent code, and you can re-produce the problem by listening on your own minimal server.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!