Receive an object over TCP/IP

后端 未结 3 1567
渐次进展
渐次进展 2021-01-19 23:35

I am going to write a program over TCP/IP and I should send objects by client or by server, It is going right when I want to send or receive strings but when I am trying to

3条回答
  •  孤独总比滥情好
    2021-01-20 00:19

    Just get rid of sending and receiving the Boolean. It's redundant. If there was some problem creating the connection, the socket wouldn't get created: an exception would be thrown instead. You're confusing everything with multiple streams on the same socket. Don't do that.

    In your read-object loop, you need to catch EOFException separately, and when you get it, close the socket and exit the loop. If you get any other IOException, log it, close the socket, and exit the loop.

提交回复
热议问题