airOnoff.java

 

/** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
    
     super.onCreate(savedInstanceState);
     setContentView(R.layout.aironoff);
 
     final  Button air_on = (Button)findViewById(R.id.airon);
  air_on.setOnClickListener(new OnClickListener(){
   public void onClick(View v){
    mes = tcpObj.mes;
    Dialog air_dlg1 = new Dialog(air_Onoff.this);
    air_dlg1.setTitle("에어콘 on/off");
    pack= new Netpakit(1,1,0, "");
    air_dlg1.setContentView(R.id.airstatus);
    airOnoff = (TextView)findViewById(R.id.airstatus);
    //Log.d("TCP", "OK");
    airOnoff.setText("on");
    air_dlg1.show();
    Thread cThread = new Thread(new TCPClient(pack));
    cThread.start();
   }
   
  });
  
  final Button air_off = (Button)findViewById(R.id.airoff);
  air_off.setOnClickListener(new OnClickListener(){
   public void onClick(View v){
    airOnoff = (TextView)findViewById(R.id.airstatus);
    airOnoff.setText("off");
   pack= new Netpakit(1,1,0,"");
   Thread cThread = new Thread(new TCPClient(pack));
   cThread.start();
   }

  });

 

TCPClient.java

 

public class TCPClient implements Runnable {
 
 Netpakit pack = null;
 String mesStr = "";
 Netpakit mes;
 //byte []mesStr = new byte[1024];
  
 public TCPClient (Netpakit p){
  pack = p;
  //mes = m;
 }
    /*
 public String getMessage(){
   //String getMes = mes.getstr();
   return getMes;
 }
 */
 public void run() {
 try {
    
  InetAddress serverAddress = InetAddress.getByName("210.102.202.47");
  Log.d("TCP", "C: Connecting....");
  Socket socket = new Socket(serverAddress, 6000);            
  
  try{
   Log.d("TCP", "C: Sending: sending");
   
    ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
    oos.writeObject(pack);
    Log.d("TCP", "C: Sent.");
   
    ObjectInputStream read= new ObjectInputStream(socket.getInputStream());
    Netpakit mes = (Netpakit) read.readObject();
    mesStr = mes.str;
    //mes = new Netpakit(0,0,0,mesStr);

    Log.d("TCP","C:Recving");
    Log.d("TCP",mes.str);
      
                
  Log.d("TCP", "C: Done.");
                 
 
            
 } catch(Exception e) {
                 
  Log.e("TCP", "S: Error", e);
              
 } finally {
                
  socket.close();
              
 }
         
 } catch (Exception e) {
              
  Log.e("TCP", "C: Error", e);
         
 }
 }

}

 

저희가 대학 졸작에 서 사용 되는 소스입니다. 간단히 말하면 홈네트워크 구현인데

output은 되는데 input이 안되네요 서버 쪽에서.. 그게 input 이 안드로이드 에뮬레이터로 안올라 오는거 같은데..

뭘 잘못 하고 있는지 ㅠㅠ