通过Wifi实现设备间的通信
服务器端,建立监听(方法更新,可以同时连接多个Client)
客户端,发送消息public class Client {private Socket socket;private BufferedReader in;private PrintWriter out;public Client(String domain, int port) {connect(domain, port);get(in);}private void connect(String domain, int port) {try {socket = new Socket(domain, port);in = new BufferedReader(new InputStreamReader(socket.getInputStream()));out = new PrintWriter(socket.getOutputStream(), true);} catch (UnknownHostException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}private void get(final BufferedReader in) {new Thread(new Runnable() {public void run() {try {String line = in.readLine();while (true) {line = in.readLine();}} catch (IOException e) {e.printStackTrace();}}}).start();}public void send(String msg) {out.println(msg);}public void disconnect() {try {out.close();in.close();socket.close();} catch (IOException e) {e.printStackTrace();}}}