자바 소켓 프로 그래 밍 에서 ObjectInputStream 과 ObjectOutputStream 의 순서 가 다 르 기 때문에 발생 하 는 차단 문제

1516 단어 socket
원본 주소:http://blog.csdn.net/redhat456/article/details/4353505
Socket 으로 통신 할 때 ObjectInputStream 과 ObjectOutputStream 을 사용 하려 면 서버 측 과 Client 측 ObjectInputStream 과 ObjectOutputStream 이 생 성 되 는 순 서 를 확보 해 야 합 니 다.
      서버 (Client) 에서 ObjectInputStream 흐름 을 생 성 할 때 클 라 이언 트 (Server) 에서 ObjectOutputStream 흐름 을 생 성 해 야 합 니 다.
      상술 한 원칙 에 따 르 면 합 법 적 인 생 성 가능 순 서 는?
      1、
            Server                          Client
            ObjectInputStream      ObjectOutputStream
            ObjectOutputStream    ObjectInputStream
 
      2、
            Server                          Client
            ObjectOutputStream    ObjectInputStream
            ObjectInputStream      ObjectOutputStream
 
     다른 상황 은 모두 차단 을 일 으 킬 수 있다.
 
    참조:

           public ObjectInputStream(InputStream in)
 throws IOException


Creates an ObjectInputStream that reads from the specified InputStream. A serialization stream header is read from the stream and verified. This constructor will block until the corresponding ObjectOutputStream has written and flushed the header.
If a security manager is installed, this constructor will check for the "enableSubclassImplementation" SerializablePermission when invoked directly or indirectly by the constructor of a subclass which overrides the ObjectInputStream.readFields or ObjectInputStream.readUnshared methods.

좋은 웹페이지 즐겨찾기