Android Socket 编程

 Socket socket = new Socket("192.168.0.116",54321);

//向服务器发送信息
     PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
     out.println(mesg);
     
     //接受服务器的信息
     BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
     String mstr=br.readLine();
     if(mstr!=null)
     {
      text1.setText(mstr);
     }else
     {
      text1.setText("数据错误");
     }
     out.close();
     br.close();
     socket.close();

你可能感兴趣的:(编程,android,socket,String,服务器,null)