java socket 一边关闭,Java socket问题半关闭

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.

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.

Really frustrated that I can't find the problem

解决方案

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值