What is the correct order of ObjectInputStream/ObjectOutputStream creation on the client and the server when sending objects over a network connection?
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 the correct order of ObjectInputStream/ObjectOutputStream creation on the client and the server when sending objects over a network connection?
- What is the difference between a client/server network and a peer-to-peer (P2P) network?
- What is the difference between a client/server network and a peer-to-peer network?