0
저는 서버/클라이언트 프로그램을 작성하고 있습니다. 클라이언트는 "Request"(이 목적을 위해 설계된 객체)를 서버에 보내고 서버는 ObjectInputStream을 사용하여 객체를 디코딩합니다. 모든 "요청"개체는 동일한 클래스이며 데이터 필드 만 다릅니다.
일반적으로 모든 것이 작동합니다. 하지만 일부 특정 상태 (어쩌면 Request 객체가 200KB 이상은 아니지만 조금 더 크다!) 서버 측의 readObject()는 예외없이 차단됩니다.
어떤 아이디어?!특정 객체에 대한 readObject() 차단
서버 코드 :
public class ConnectionThread extends Thread {
Socket con;
Request request;
public ConnectionThread(Socket s) {
con = s;
try {
ObjectInputStream in = new ObjectInputStream(con.getInputStream());
// Works till here; the object "in" is initialized.
request = (Request) in.readObject();
// This line is not reached, in particular cases.
} catch (ClassNotFoundException ex) {
Logger.getLogger(ConnectionThread.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(ConnectionThread.class.getName()).log(Level.SEVERE, null, ex);
}
}
...
}
클라이언트 코드 :
public static void saveStoreDataForTable(DataTable tb) {
try {
Socket s = new Socket("localhost", portNo);
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
out.writeObject(new Request("saveStoreData",
new Object[]
{tb.getEdited(), tb.getRemoved(), tb.getNewTables(), tb.getAlterations()}));
out.flush();
// These lines work. But I can't get servers respone; again, in some particular cases.
...
}
여기 내가 필요로하는 것은 Exception을 가진 catch가 생각한 적이없는 다른 예외를 잡는 것입니다. 아마도 in.readObject()가 "Request"유형의 객체를 반환하지 않을 수도 있습니다. –
'readObject()'는 '특정 객체를 차단하지 않습니다'. 수신 할 데이터가 없을 때 차단됩니다. – EJP