本文介绍了java.net.SocketException:socket关闭TCP客户端服务器通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在TCP上创建一个java客户端/服务器应用程序,其中有两个套接字: 一个用于交换消息。 li> 两个用于文件传输。 我在服务器创建了两个ServerSockets,通过接受ServerSockets。 首先,客户端通过第一个Socket 发送一些字节它可以告诉服务器它需要哪个文件。 然后服务器通过第二个套接字发送文件到客户端。 客户端接收该文件尝试将传送完成消息发送回服务器。 在那里我得到了关闭套接字的异常。 但是我从来没有关闭套接字。 我只关闭了放置文件的缓冲区。 即使我尝试在我发送文件后再次打开socketInputStream,错误仍然是相同的。 此外,如果我不关闭文件所在的缓冲区,客户端不会得到该文件。 服务器异常 我做错了什么?解决方案套接字关闭异常表示捕获异常的应用程序关闭套接字,然后继续尝试使用它。您可能不知道关闭套接字的输入或输出流也会关闭其他流和套接字。对于软件导致的连接中止,请参见重复的链接。 I am creating a java client/server application over TCP where we have two sockets:One is for exchanging messages.Two is for file transfer.I have created in the Server two ServerSockets in order to create Socket One and Twoby accepting the ServerSockets.At first the client sends some bytes through the first Socketso that it can tell the Server which file it needs.Then the Server through the second socket sends the file to the client.After the client receives the file tries to send back to the server a Transfer Done Message.There I get the Exception for the closed socket.However I never close the socket up until now.I only close the buffer which sents the file.Even if I try to open again the socketInputStream after I sent the file the error is still the same.Also if I do not close the buffer which sents the file, the client does not get the file.Server ExceptionClient ExceptionWhat am I doing wrong? 解决方案 A 'Socket closed' exception means that the application that caught the exception closed the socket and then kept trying to use it. You may be unaware that closing the input or output stream of a socket closes the other stream and the socket as well. For 'software caused connection abort' see the duplicate link. 这篇关于java.net.SocketException:socket关闭TCP客户端服务器通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-06 03:06