首页 > 解决方案 > 为什么我尝试发送数据时出现“setCommandByIoctl failed”?

问题描述

我正在编写代码以将数据从客户端发送到服务器。但是,当我尝试向服务器发送数据时,遇到以下错误。我确信连接已经建立。我已经在 Internet 上搜索了有关该错误的信息。但是,以前没有遇到过这样的错误。

这是错误的logcat:

W/e.magickeyboard: type=1400 audit(0.0:52635): avc: denied { ioctl } for pid=18094 path="/proc/18094/rtg" dev="proc" ino=1605802 ioctlcmd=0xab20 scontext=u:r:untrusted_app:s0:c182,c256,c512,c768 tcontext=u:r:untrusted_app:s0:c182,c256,c512,c768 tclass=file permissive=0
D/RtgSchedIpcFile: setCommandByIoctl failed ret:-1, cmdid:32, errno:13
V/AudioManager: querySoundEffectsEnabled...
D/RtgSchedIpcFile: setCommandByIoctl failed ret:-1, cmdid:32, errno:13
W/e.magickeyboard: type=1400 audit(0.0:52636): avc: denied { ioctl } for pid=18094 path="/proc/18094/rtg" dev="proc" ino=1605802 ioctlcmd=0xab20 scontext=u:r:untrusted_app:s0:c182,c256,c512,c768 tcontext=u:r:untrusted_app:s0:c182,c256,c512,c768 tclass=file permissive=0
D/RtgSchedIpcFile: setCommandByIoctl failed ret:-1, cmdid:32, errno:13
W/e.magickeyboard: type=1400 audit(0.0:52637): avc: denied { ioctl } for pid=18094 path="/proc/18094/rtg" dev="proc" ino=1605802 ioctlcmd=0xab20 scontext=u:r:untrusted_app:s0:c182,c256,c512,c768 tcontext=u:r:untrusted_app:s0:c182,c256,c512,c768 tclass=file permissive=0
W/e.magickeyboard: type=1400 audit(0.0:52638): avc: denied { ioctl } for pid=18094 path="/proc/18094/rtg" dev="proc" ino=1605802 ioctlcmd=0xab20 scontext=u:r:untrusted_app:s0:c182,c256,c512,c768 tcontext=u:r:untrusted_app:s0:c182,c256,c512,c768 tclass=file permissive=0
D/RtgSchedIpcFile: setCommandByIoctl failed ret:-1, cmdid:32, errno:13
D/RtgSchedIpcFile: setCommandByIoctl failed ret:-1, cmdid:32, errno:13
W/e.magickeyboard: type=1400 audit(0.0:52639): avc: denied { ioctl } for pid=18094 path="/proc/18094/rtg" dev="proc" ino=1605802 ioctlcmd=0xab20 scontext=u:r:untrusted_app:s0:c182,c256,c512,c768 tcontext=u:r:untrusted_app:s0:c182,c256,c512,c768 tclass=file permissive=0
D/RtgSchedIpcFile: setCommandByIoctl failed ret:-1, cmdid:32, errno:13
D/RtgSchedIpcFile: setCommandByIoctl failed ret:-1, cmdid:32, errno:13
D/RtgSchedIpcFile: setCommandByIoctl failed ret:-1, cmdid:32, errno:13
D/RtgSchedIpcFile: setCommandByIoctl failed ret:-1, cmdid:32, errno:13
D/RtgSchedIpcFile: setCommandByIoctl failed ret:-1, cmdid:32, errno:13
D/RtgSchedIpcFile: setCommandByIoctl failed ret:-1, cmdid:32, errno:13

我不知道这是什么意思。

这是我构建套接字以连接到服务器的客户端代码:

btnConnect = (Button) findViewById(R.id.connect);
    btnConnect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            
            mThreadPool.execute(new Runnable() {
                @Override
                public void run() {

                    try {                            
                        socket=new Socket("192.168.101.2",9102);
                        System.out.println(socket.isConnected());
                        boolean m=socket.isConnected();
                        if(m) {
                            Log.d("Connect","True");
                        }
                        if(!m){
                            Log.d("Connect","Connect false");
                        }


                    } catch (IOException e) {
                        e.printStackTrace();
                        Log.d("Connect",Log.getStackTraceString(e));
                    }
                    catch(NullPointerException e){
                        Log.d("Connect",Log.getStackTraceString(e));
                    }
                    catch(NetworkOnMainThreadException e){
                        Log.d("Connect",Log.getStackTraceString(e));
                    }

                }
            });

        }
    });

下面是我将数据传输到服务器的客户端代码:

btnSend = (Button) findViewById(R.id.send);
    btnSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {                
            mThreadPool.execute(new Runnable() {
                @Override
                public void run() {

                    try {
                
                        outputStream = socket.getOutputStream();
                        outputStream.write(floatToByte(a));
                        outputStream.flush();

                    } catch (IOException e) {
                        Log.d("send",Log.getStackTraceString(e));
                    }
                    catch(NullPointerException e)
                    {
                        Log.d("send",Log.getStackTraceString(e));
                    }

                }

这是我的服务器的代码:

try {
            
            ServerSocket serverSocket=new ServerSocket(9102);
            
            Socket socket=serverSocket.accept();
         
            InputStream is=socket.getInputStream();
            BufferedReader br=new BufferedReader(new InputStreamReader(is));

            String info=null;
            while(!((info=br.readLine())==null)){
                System.out.println("This is the server:"+info);
            }
           
            OutputStream os=socket.getOutputStream();
            PrintWriter pw=new PrintWriter(os);
         
            String reply="welcome";
            pw.write(reply);
            pw.flush();
         
            pw.close();

            br.close();
            is.close();

        } catch (IOException e) {
            e.printStackTrace();
        }


}

标签: androidsockets

解决方案


推荐阅读