자바 소켓 프로 그래 밍 에서 ObjectInputStream 과 ObjectOutputStream 의 순서 가 다 르 기 때문에 발생 하 는 차단 문제
1516 단어 socket
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.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
React 구성 요소에서 소켓 이벤트 리스너가 여러 번 실행됩니다.기본적이지만 종종 간과되는 사이드 프로젝트를 하면서 배운 것이 있습니다. 이 프로젝트에는 단순히 두 가지 주요 부분이 포함되어 있습니다. 프런트 엔드: 반응 및 재료 UI 백엔드: Express, Typescript...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.