简体   繁体   中英

Clarifications while reading/writing Java socket streams

I have few questions in java socket programming.

  1. while reading the inputstream in client socket, if it throws IO exception; then do we need to reconnect the server socket/ reintialize the client socket again?

  2. if we close the output stream, will it closes the client socket?

  3. in client socket, if the message read from the inputstream is different as what we expected; do we have any standard to handle this?

while reading the inputstream in client socket, if it throws IO exception; then do we need to reconnect the server socket/ reintialize the client socket again?

Yes, unless it was a SocketTimeoutException on a read operation.

if we close the output stream, will it closes the client socket?

Yes.

in client socket, if the message read from the inputstream is different as what we expected; do we have any standard to handle this?

No. If the message is completely unrecognizable, you wil probably want to sever the connection. If it's a recognized message but out of sequence, it may be either a programming error or a condition you didn't think of during design. Solution: think about it now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM