ObjectInputStream(socket.getInputStream()); does not work

后端 未结 1 1767
误落风尘
误落风尘 2020-12-03 15:41


I\'m programming a class to communicate to a server but when it tries to construct the ObjectInputStream with the help of the inputstream the program is freezing. There

相关标签:
1条回答
  • 2020-12-03 16:13

    The ObjectInputStream constructor reads data from the given InputStream. In order for this to work, you must flush the ObjectOutputStream immediately after construction (to write the initial header) before you attempt to open the ObjectInputStream. Also, if you want to send more than one object per connection, you must open the ObjectOutputStream once and use it for the lifetime of the socket (e.g. your shareToAll method).

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