Java socket问题半关闭 [英] Java socket problems half closing

查看:263
本文介绍了Java socket问题半关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JDK 1.3(BD-J平台)使用tcp套接字。

I'm using JDK 1.3 (BD-J platform) using tcp sockets.

我似乎在客户端收到一些错误。如果我已完成写入并关闭较低的套接字输出流,我似乎尝试从服务器端读取异常(大多数消息如果没有关闭则通过),但是当它关​​闭时我遇到了麻烦。

I seem to be getting some errors half closing on the client end. If I'm done writing and close the lower socket output stream, I seem to get an exception trying to read from the server end (most messages go through if it's not closed), but when it's closed I run into troubles.

尝试使用服务器进行调试,即使套接字关闭,我也不应该读取客户端发送的所有内容吗?只需在服务器端使用低套接字输入流。如果我正常运行它得到大多数消息,尝试在调试器中运行服务器我得到1消息然后一个Socket异常连接重置。

Attempting to debug with the server, shouldn't I be able to read everything the client sends even if the socket is closed? Just using the low socket Input stream on the server side. If I run it normally I get most message, attempt to run the server in the debugger I get 1 message then a Socket Exception Connection Reset.

这是客户端上的部分代码,它发送消息然后在完成写入时关闭,等待所有输入完成然后完全关闭套接字。

Here is partial code on the client end of how it sends messages then closes when it's done writing, waits for all input to finish then closes the socket entirely.

http://pastie.org/private/cwc5uijl1x2ndwjwsun4lg

我无法找到问题真的很沮丧

Really frustrated that I can't find the problem

推荐答案

您需要 Socket.shutdownOutput 。关闭 InputStream Socket OutputStream 关闭套接字(疯狂但真实)。

You need Socket.shutdownOutput. Closing either the InputStream or the OutputStream of a Socket closes the Socket (crazy, but true).

这篇关于Java socket问题半关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆