안드로이드 펍에서 받았던 채팅 소스를 제가 조금 건들여 봤습니다


에뮬에서 에딧 텍스트 뷰의 텍스트를 버튼을 누르면 텍스트 뷰에 보여야 하는데 


로컬호스트로도 만들고 해서 분명 그렇게 보일 거라 생각했는데 안되더라구요


제가 초보이기도 하고 잘 모르니 지적 부탁드리겠습니다.


 public class NetA extends Activity {
    /** Called when the activity is first created. */
	
	InetAddress ia;
	String ip;
	InputStream in;
	OutputStream out;
	int port = 8080;
	Socket socket;
	String msg;
	private EditText edit;
	private TextView text;
	
	private final Handler handle=new Handler();
	
	@Override
	protected void onStop(){
		super.onStop();
		try{
			socket.close();
		}catch(Exception e){e.printStackTrace();}
	}
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Thread threadc = new Thread(){
			public void Run(){
				try {
					ia = InetAddress.getLocalHost();
					ip = ia.toString();		
					connect(ip, port);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		};
		threadc.start();
        
		edit= (EditText)findViewById(R.id.edit);
		Button btn = (Button)findViewById(R.id.btn);
		text = (TextView)findViewById(R.id.text);
		
		btn.setOnClickListener(new OnClickListener(){
			public void onClick(View v){
				if(socket != null && socket.isConnected()){
					try {
						PrintWriter outp = new PrintWriter(new BufferedWriter(
						new OutputStreamWriter(socket.getOutputStream())), true);
						String msg = edit.getText().toString();
						outp.println(edit.getText().toString());
						outp.flush();
						text.append(msg);
						edit.setText("", TextView.BufferType.NORMAL);
						
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					
				}
			}
		});
		
		
    }
    private void connect(String ip, int port){
    	int size;
    	byte[] bt = new byte[10240];
    	msg="";
    	try {
			socket = new Socket(ip, port);
			in = socket.getInputStream();			
			out = socket.getOutputStream();
			
			while(socket !=null && socket.isConnected()){
				size = in.read(bt);
				if(size <= 0)continue;
				msg = new String(bt, 0, size, "UTF-8");
				handle.post(new Runnable(){
					public void run() {
						text.setText(
						text.getText()+msg+System.getProperty("line.separator"));
						
					}
					
				});
				
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
    }
}