server:
   
      public class main { public static void main(String[] args) {
// TODO Auto-generated method stub ServerSocket ss=null;
Socket s = null;

DataInputStream dis =null;
DataOutputStream dos = null;

//监听端口
try {
ss = new ServerSocket(1234);
} catch (IOException e) {e.printStackTrace();}

while(true){
try {
s = ss.accept();

dis =new DataInputStream(s.getInputStream());
dos = new DataOutputStream(s.getOutputStream());

System.out.println("服务端接收的信息是:"+dis.readUTF());
dos.writeUTF("我收到你的消息。土豆!");

   } catch (IOException e) {e.printStackTrace();}
}
}
}Client:
            public class Main extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
Button button;
EditText edit;
TextView  text;
Socket socket;

DataInputStream dis = null;
DataOutputStream dos = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        edit = (EditText) findViewById(id.edit);
        text = (TextView) findViewById(id.text);
        
        button = (Button) findViewById(id.button);
        button.setOnClickListener(this);
    } public void onClick(View v) {
// TODO Auto-generated method stub
if(v==button){
try {
socket = new Socket("192.168.11.12",1234);

dis = new DataInputStream(socket.getInputStream());
dos = new DataOutputStream(socket.getOutputStream());

} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

//发送信息
try {
dos.writeUTF(edit.getText().toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
//接收信息
  try {
text.setText(dis.readUTF().toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
}
结果是[2010-12-16 15:36:01 - Emulator] Warning: No DNS servers found!