c2dm을 이용한 채팅을 구현중입니다.

 

현재는 모든 구현이 완료된 상태인데요.

 

디바이스 아이디와 토큰등 디비에 저장후 메시지를 보내는 방식으로 처리하였습니다.

 

그런데.. 메세지를 send 할때 아래처럼 구현이 되었는데요..

 

public void sender(String regId, String authToken, String msg)
   throws Exception {

  Random rnd = new Random();
  int Rcode = rnd.nextInt(10000) + 1;

  Log.v("c2dmid_", Integer.toString(Rcode));

  StringBuffer postDataBuilder = new StringBuffer();
  postDataBuilder.append("registration_id=" + regId);  

  postDataBuilder.append("&collapse_key=" + Rcode);
  postDataBuilder.append("&delay_while_idle=2");
  postDataBuilder.append("&data.msg=" + URLEncoder.encode(msgg, "UTF-8"));

  byte[] postData = postDataBuilder.toString().getBytes("UTF8");
  URL url = new URL("https://android.apis.google.com/c2dm/send");
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.setDoOutput(true);
  conn.setUseCaches(false);
  conn.setRequestMethod("POST");
  conn.setRequestProperty("Content-Type",
    "application/x-www-form-urlencoded");
  conn.setRequestProperty("Content-Length",
    Integer.toString(postData.length));
  conn.setRequestProperty("Authorization", "GoogleLogin auth="
    + authToken);
  OutputStream out = conn.getOutputStream();
  out.write(postData);
  out.close();
  conn.getInputStream();

  chatmsg.setText("");
 }

버튼 클릭시 sender가 호출되어 실행됩니다.

그런데 카톡처럼 좀 빠르게 구현을 하려고 하는데요..

위의 방식은 버튼클릭시 약 1~2초정도 텀이 발생합니다.(버튼클릭후 처리하기까지 대기상태)

 

어찌하면 버튼클릭시 텀 없이 계속해서 실행할 수 있을까요..?