글쓴이 :박찬우 2000년 5월 12일 14:02:05
In Reply to: 오브젝트스트림에 대해 궁금해서리.. posted by 정해영 on 2000년 5월 12일 11:02:57:
애플릿 그룹 채팅인데
클라이언트와 서버간의 정보 교환을
객체를 이용하여 하고 있습니다.
기존 책들이 스트링을 넘기고 StringTokenizer로
프로토콜 분석해서 채팅을 하는 방식을 탈피했지요.
다음은 그 소스입니다.
package metronia6.data;
import java.io.Serializable;
//Integer
public class Command implements Serializable {
private int commandValue;
private Result result;
private String[] args = {""};
//command numbers
public static final int LOGIN = 10;
public static final int LOGOUT = 20;
public static final int DESTROY = 25;
public static final int STOP = 26;
public static final int CHAT = 30;
//CLIENTLIST, ROOMLIST
public static final int CLIENTLIST = 40;
public static final int ROOMLIST = 50;
public static final int CLIENT_DBL_CLICK = 45;
public static final int ROOM_DBL_CLICK = 55;
public static final int ENTEROOM = 60;
public static final int MAKEROOM = 70;
public static final int ROOM_CONFIG = 71;
public static final int OUTROOM = 80;
//일반인 특수기능
public static final int EAR_CHAT = 100;
public static final int WARNING = 190;
//관리자 특수기능
public static final int CLIENT_OUT = 210;
//초대/찾기/메시징 대화상자에서의 명령 코드
public static final int INVITE_LOADING = 300; //초대 대화상자를 띄울 때
public static final int INVITE_CLIENT_CLICK = 310; //메시지 창에서 특정 손님 클릭. 서버는 그 손님을 찾아서 저장한다.
public static final int INVITE_INVITE = 320; //메시지 창에서의 초대
public static final int INVITE_ID_FIND = 330; //메시지 창에서의 id 찾기
public static final int INVITE_MULTI_FIND = 340; //ID가 아닌 다른 다중 조건으로 찾기
public static final int INVITE_CHAT = 350; //메시지 창에서의 채팅
public static final int ONE2ONE_REQUEST = 121; //일대일 대화 신청 명령 코드
public static final int ONE2ONE_REQUEST_YES = 122;
public static final int ONE2ONE_REQUEST_NO = -122;
//메시징 받을 때 뜨는 다이어로그를 위한 명령 코드
public static final int INVITE_CLOSING = 360;
public static final int CHECK_MESSAGING = 370;
//메시지 수신 거부 여부
public static final int MESSAGE_STOP = 400;
/**생성할 때 명령을 결정한다.*/
public Command(int command) {
commandValue = command;
result = new Result();
}
/**원하는 명령이 무엇인지 알기 위한 메서드*/
public int getCommandValue() {
return commandValue;
}
/**이 곳에 명령 수행에 필요한 정보들을 넘겨준다.*/
public void setArgs(String[] params) {
args = params;
}
/**명령 수행 전에 해독*/
public String[] getArgs() {
return args;
}
/**원하는 넣거나 얻기 위해 결과 벡터에 접근할 메서드*/
public Result getResult() {
return result;
}
/***/
public void setResult(Result result) {
this.result = result;
}
}
이 것을 보내는 것은 쉽지요.
out.writeObject(command);를 이용하면 됩니다.
아래 사이트로 오셔서 테스트해보기 바랍니다.
만일 인증 시간이 오래 걸린다면 서버가 기동되지
않은 경우일 가능성이 많습니다.