제가 안드로이드로 원격제어를 해보고있는데요

NIO를 이용해서요 

PC는 서버로두고 안드로이드에뮬은 클라이언트로 해서

안드로이드에서 메시지를 보내면 PC서버에서 잘받는데 

서버에서 받고 다시 안드로이드로 보내면 메세지를 받지못하고 NULL값이 찍힙니다...

제가 통신 완전 초보라....혹시 알고계시는분 부탁드립니다..



 
--- Server ---
 package android;

import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.SocketException;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;

public class RemoteServer {
 public static void main(String[] args) {
  Function function = new Function();
  function.start();
 }
}
class Function extends Thread {
 private Robot robot = null;
 private Toolkit toolkit = null;
 private int conW, conH;
 DatagramChannel channel;
 ByteBuffer buffer;

 final byte CONNECT_PAGE = 00;
 final byte MOTION_PAGE = 10;
 final byte MOUSE_LEFT = 11;
 final byte MOUSE_RIGHT = 12;
 final byte VPLAYER_PAGE = 20;
 final byte VPLAYER_PLAY = 21;
 final byte VPLAYER_STOP = 22;
 final byte VPLAYER_POWER = 28;


 public Function() {
  super();
  try {
   channel = DatagramChannel.open();
   channel.socket().bind(new InetSocketAddress("172.16.4.15", 9000));
   channel.configureBlocking(true);
   buffer = ByteBuffer.allocateDirect(1024);
   robot = new Robot();
  } catch (Exception e) {
   e.printStackTrace();
  }
  toolkit = Toolkit.getDefaultToolkit();
 }
 public void run() {
  while (true) {
   try {
    buffer.clear();
    //패킷을 받는다.
    SocketAddress addr = channel.receive(buffer);
    if(addr != null){
     buffer.flip();
     byte[] bb = new byte[buffer.limit()];
     buffer.get(bb, 0, buffer.limit());
     String str = new String(bb);
     String[] requestMsg = str.split("@");

     switch (Byte.valueOf(requestMsg[0])) {
     case CONNECT_PAGE:
      System.out.println("CONNECT_PAGE");
      buffer.clear();
      buffer.put("success".getBytes());
      buffer.flip();
      channel.send(buffer, addr);
      System.out.println(addr);
     
      this.conW = Integer.parseInt(requestMsg[1]);
      this.conH = Integer.parseInt(requestMsg[2]);
      break;
     case MOTION_PAGE:
      System.out.println("MOTION_PAGE");
      try {
       setMouseMove(Integer.parseInt(requestMsg[1]), Integer
        .parseInt(requestMsg[2]));
      } catch (Exception e) {}
      break;
     case MOUSE_LEFT:
      System.out.println("MOUSE_LEFT");
      setMouseClick(InputEvent.BUTTON1_MASK);
      break;
     case MOUSE_RIGHT:
      System.out.println("MOUSE_LEFT");
      setMouseClick(InputEvent.BUTTON3_MASK);
      break;
     case VPLAYER_PLAY:
      System.out.println("VPLAYER_PLAY");
      setMouseClick(InputEvent.BUTTON3_MASK);
      break;
     case VPLAYER_STOP:
      System.out.println("VPLAYER_PLAY");
      setMouseClick(InputEvent.BUTTON3_MASK);
      break;
     case VPLAYER_POWER:
      System.out.println("VPLAYER_POWER");
      setKeyPressPlay(KeyEvent.VK_ESCAPE);
      break;
     }
    }else{
     continue;
    }
   } catch (Exception e) {
    e.printStackTrace();
   }
  }
 }
 
 // 마우스 움직임
 public void setMouseMove(int x, int y) {
  try {
   int rW = this.toolkit.getScreenSize().width;
   int rH = this.toolkit.getScreenSize().height;

   int cX = (int) (x * (float) ((float) rW / (float) this.conW));
   int cY = (int) (y * (float) ((float) rH / (float) this.conH));

   robot.mouseMove(cX, cY);
  } catch (HeadlessException he) {}
 }
 // 마우스 클릭
 public void setMouseClick(int buttons) {
  robot.mousePress(buttons);
  robot.mouseRelease(buttons);
 }
 // 키 프레스
 public void setKeyPressPlay(int keys) {
  robot.keyPress(keys);
 }
}


-- Client --
 package android.remote;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;

public class ConnectPage extends MyActivity{
 private static final String tag = "ConnectPage";
 private Display display;
 LinearLayout linearLayout;
 private EditText conn_et;
 private DatagramChannel channel;
 private InetAddress serverIp;
 private ByteBuffer buffer;

 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.connect);
  display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
    .getDefaultDisplay(); // 단말기 display 객체
  Button conn_btn = (Button) findViewById(R.id.conn_btn); // 연결 버튼
  conn_btn.setOnClickListener(new View.OnClickListener() {
   ConnectPage connectPage = new ConnectPage();

   public void onClick(View v) {
    conn_et = (EditText) findViewById(R.id.conn_et); // ip EditText
    try {
     serverIp = InetAddress.getByName(conn_et.getText().toString());

     channel = DatagramChannel.open();
     channel.configureBlocking(false); 
     SocketAddress sa = new InetSocketAddress(conn_et.getText() .toString(), 9000);
     buffer = ByteBuffer.allocateDirect(1024);
     
     buffer.clear();
     
     String responseMsg = connectPage.CONNECT_PAGE + "@" +
     (display.getWidth() - 100) + "@" + display.getHeight();
     // server로 보낼 메시지
     
     buffer.put(responseMsg.getBytes()); 
     buffer.flip();
     channel.send(buffer, sa);

     buffer.clear();
     SocketAddress addr = channel.receive(buffer);
     if (addr != null) {
      buffer.flip();
      byte[] cc = new byte[buffer.limit()];
      buffer.get(cc, 0, buffer.limit());
      String returnMSG = new String(cc);
      if ("success".equals(returnMSG)) {
       Toast t = Toast.makeText(ConnectPage.this, "연결되었습니다",
        Toast.LENGTH_SHORT);
       t.show();
       moveMotionPage();
      } else {
       Toast t = Toast.makeText(ConnectPage.this, "연결실패",
        Toast.LENGTH_SHORT);
       t.show();
      }
     } else {
      Toast t = Toast.makeText(ConnectPage.this,
       "channel연결실패", Toast.LENGTH_SHORT);
      t.show();
     }
    } catch (UnknownHostException ue) {
    } catch (SocketException se) {
    } catch (IOException ie) {
    }
   }
  });
 }

 protected void onPause() {
  super.onPause();

  SharedPreferences pre = getSharedPreferences("SaveState", 0);
  SharedPreferences.Editor edit = pre.edit();
  // 상태값 저장
  String tempIp = conn_et.getText().toString();
  edit.putString("serverIp", tempIp);
  // edit.putString("serverIp", "TEST");
  // edit.putInt("serverPort", 9000);
  edit.commit();
 }
}