Thread th = new Thread(new Runnable() {
@Override
public void run() { // 서버로부터 계속해서 메시지 받기 대기.
try {
while (true) {
Object obj = ois.readObject();
if(obj.getClass().getName().equals("com.example.user.carpool_client.SendObject")){
so = (SendObject)obj;
System.out.println("서버로 부터 받은 메시지 : " + so.msg);
new Client_Protocol(so.msg);
}else if(obj.getClass().getName().equals("java.util.Vector")){
Vector<MakeInfo> vc_MakeInfo = (Vector<MakeInfo>)obj;
helper h = new helper();
h.arriveVector = true;
// for(int i=0;0<vc_MakeInfo.size();i++){
// h.Static_Request_MakeInfo.add(vc_MakeInfo.elementAt(i));
// }
System.out.println("벡터 초기화");
// Progress_Handler.sendEmptyMessage(1);
}
}
} catch (ClassCastException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (EOFException e) {
e.printStackTrace();
} catch (SocketException e) {
try {
oos.close();
ois.close();
socket.close();
} catch (IOException e1) {
e1.printStackTrace();
}
} catch (IOException e) {
try {
oos.close();
ois.close();
socket.close();
e.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
});
th.start();
public class Client_Protocol {
StringTokenizer token = null;
Client_Protocol(String msg) {
String fp = "";//First Protocol
String n_message = "";//next Protocol message
token = new StringTokenizer(msg, "/");
fp = token.nextToken();
n_message = token.nextToken();
if (fp.equals("LOGINPAGE")) {
Login_protocol(n_message);
} else if (fp.equals("CREATEPAGE")) {
Id_Check(n_message);
}
}//Protocol Constructor end
// Client_Protocol(Vector<MakeInfo> vc_MakeInfo){
// helper h = new helper();
// h.Static_Request_MakeInfo = vc_MakeInfo;
// arriveVector = true;
// System.out.println("벡터 초기화");
// }
private void Login_protocol(String m) {
token = new StringTokenizer(m, "@");
String protocol = token.nextToken();
String msg = token.nextToken();
if (protocol.equals("ISRIGHT") && msg.equals("true")) {//Carpool main 점 시작.
intent = new Intent(getApplicationContext(), Carpool_main_Activity.class);
so.msg = "REQUEST_INFO/" + editText_id.getText().toString();
send_toServer(so); //사용자의 정보를 얻어옵니다.
} else if (protocol.equals("ISRIGHT") && msg.equals("false")) {
println("계정 정보가 틀렸습니다.");
} else if (protocol.equals("ISRIGHT") && msg.equals("notfound")) {
println("아이디가 틀렸습니다.");
} else if (protocol.equals("LOGIN")) {
intent.putExtra("SendObject",so);
SharedPreferences pref = getSharedPreferences("pref", 0);
SharedPreferences.Editor editor = pref.edit();
editor.putString("ID",so.id);
editor.commit();
send_toServer("REQUEST_ROOM_INFO/NO_MEANING");
Progress_Handler.sendEmptyMessage(0);
while(true){
if(!helper.arriveVector){
// System.out.println("while 도는중");
}else{
Progress_Handler.sendEmptyMessage(1);
break;
}
}
System.out.println("액티비티 실행");
}
}//Login_protocol end
private void Id_Check(String m) {
if (m.equals("EXIT")) {
helper.g_msg = m;
System.out.println(" GLobal Mesaage change");
} else {
helper.g_msg = m;
System.out.println(" GLobal Mesaage change");
}
}
}
첫번째 코드에서 readobject를 받아오는데, 제가 두번째 코드에서 while문을 걸어버리면 readobject받아오는 녀석이 파업하고 서버에서 보내도 받아오질 않네요 .. 한달째 보고있는데 도대체 왜이러는걸까요??
일단 저걸 하는 이유는 processdialog를 띄우는동안에 메인을 멈춰놓고 저 쓰레드에서 데이터를 받아오면 그때부터 실행하게끔 하고싶은데.. 도저희 방법을 모르겠네요..
아 그리고 에러는 발생하지않았습니다.