java.io.EOFException when try to read from a socket

后端 未结 4 623
[愿得一人]
[愿得一人] 2020-12-19 12:02

i don\'t know why java.io.EOFException appear. i want to write a file after i get binary stream from server.

Here\'s my code

inputSt         


        
4条回答
  •  星月不相逢
    2020-12-19 12:25

    It depends when you use client - server implementation and client is "always up" and socket is keeping whole time.

    if socket connection is up and you use for example ObjectInputStream so "EOFException" will appear when client close socket (socket.close) or "java.net.SocketException: Connection" reset will apper when socket.close() isnt check at finally for sure...

    But if you keep client and socket connection up ObjectInputStream.readObject() will stay and listen what is what you want in this scenario. and yes when you call only read() you will get -1 and if client is killed and you are handling for one client one thread at server you will only get -1 and thread will live foreever (if you dont kill it manualy or kill whole server)

提交回复
热议问题