Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What is the correct order of ObjectInputStream/ObjectOutputStream creation on the client and the server when sending objects over a network connection?

0
Posted

What is the correct order of ObjectInputStream/ObjectOutputStream creation on the client and the server when sending objects over a network connection?

0

Location: http://www.jguru.com/faq/view.jsp?EID=333392 Created: Feb 19, 2001 Modified: 2001-08-18 18:55:36.37 Author: Tim Rohaly (http://www.jguru.com/guru/viewbio.jsp?EID=10) Question originally posed by Joen Moreno (http://www.jguru.com/guru/viewbio.jsp?EID=134600 According to the API documentation for ObjectInputStream’s constructor: The stream header containing the magic number and version number are read from the stream and verified. This method will block until the corresponding ObjectOutputStream has written and flushed the header. This is a very important point to be aware of when trying to send objects in both directions over a socket because opening the streams in the wrong order will cause deadlock. Consider for example what would happen if both client and server tried to construct an ObjectInputStream from a socket’s input stream, prior to either constructing the corresponding ObjectOutputStream. The ObjectInputStream constructor on the client would block, waiting for the m

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123