Socket program to send and receive user defined objects not working

后端 未结 1 813
深忆病人
深忆病人 2020-12-18 13:57

I have a user defined class Message, whose object I would like to pass between the client and the server.

The Message class is as follows:

import jav         


        
相关标签:
1条回答
  • 2020-12-18 14:22

    You need to create the ObjectOutputStream before the ObjectInputStream at both ends.

    The reason is that, as described in the Javadoc, the respective constructors write and read a stream header. So the input stream constructor can't return until the output stream constructor at the peer has executed. So if you construct both input streams first there is a deadlock.

    0 讨论(0)
提交回复
热议问题