如何在java scoket中获取连接到android移动热点的客户端ip?

时间:2016-12-29 05:18:08

标签: java android sockets ip

有没有办法在java scoket中获取连接到android热点的客户端ip,我必须在提交时将输入值发送到客户端ip

这是我试过的:

private class AttemptSubmit {

    public  ArrayList<String> getClientList1() {
        ArrayList<String> clientList = new ArrayList<>();
        BufferedReader br = null;
        try {
            br = new BufferedReader(new FileReader("/proc/net/arp"));
            String line;
            while ((line = br.readLine()) != null) {
                String[] clientInfo = line.split(" +");
                String mac = clientInfo[3];
                if (mac.matches("..:..:..:..:..:..")) {
                    clientList.add(clientInfo[0]);
                    // TODO Auto-generated method stub
                    Socket socket = null;
                    DataOutputStream dataOutputStream = null;
                    DataInputStream dataInputStream = null;

                    try {
                        socket = new Socket(clientInfo[0], 8888);
                        dataOutputStream = new DataOutputStream(socket.getOutputStream());
                        dataInputStream = new DataInputStream(socket.getInputStream());
                        dataOutputStream.writeUTF(editUsername.getText().toString());
                        dataOutputStream.writeUTF(editPassword.getText().toString());
                    } catch (UnknownHostException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    finally{
                        if (socket != null){
                            try {
                                socket.close();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }

                        if (dataOutputStream != null){
                            try {
                                dataOutputStream.close();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }

                        if (dataInputStream != null){
                            try {
                                dataInputStream.close();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
        } catch (java.io.IOException aE) {
            aE.printStackTrace();
            return null;
        }
        return getClientList1();
    }

提交行动:

btnSubmit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            AttemptSubmit attemptSubmit= new AttemptSubmit();
            attemptSubmit.getClientList1();
        }
    });

问题是,当我点击提交按钮时,我收到此错误&#34;不幸的是,Aqua已经弯腰。&#34;

0 个答案:

没有答案