1

Android (3.2) Phonegap プラグインに大きな問題があります。

TCP ソケットを開き、コマンドを送信して応答を受信し、それを JS スクリプトに渡すプラグインを作成しました。

try {
        int port  = args.getInt(0);
        String host = args.getString(1);
        String message = args.getString(2);
        boolean is_pure_text = args.getBoolean(3);
        static Socket sock;
        String reply;

        try {

            if(sock==null || sock.isClosed()){

                sock = new Socket(host, port);
                sock.setSoTimeout(1000);
                Log.d("TCPSockets", "Socket created");

            }

            DataOutputStream dataOutputStream = new DataOutputStream(sock.getOutputStream());;
            DataInputStream dataInputStream = new DataInputStream(sock.getInputStream());


            Log.d("TCPSockets", "Created reader/writer");

            dataOutputStream.writeUTF(message);

            Log.d("TCPSockets", "Sent message");


            reply="";
            int i;
            int tmp;
            byte[] b = new byte[40];
            for(i=0;i<39;i++){
                tmp=dataInputStream.readUnsignedByte();
                Log.d("TCPSockets", "READED BYTE: "+tmp);
                b[i]=(byte)tmp;
            }

            byte[] buffer = new byte[i];

            System.arraycopy (b, 0, buffer, 0, i);

            reply = new String(buffer, "US-ASCII");

            callbackContext.success(reply);

            Log.d("TCPSockets", "Received reply: " + reply);

        } catch (UnknownHostException e) {
            Log.d("TCPSockets", "Unknown Host "+host+":"+port);
            callbackContext.error("Unknown Host "+host+":"+port);
        } catch (IOException e) {
            Log.d("TCPSockets", e.getMessage());
            callbackContext.error(e.getMessage());
        } catch(Exception e){
            Log.d("TCPSockets", "Errore Generico "+e.getMessage());
            callbackContext.error("Errore Generico "+e.getMessage());
        }

走ると……

02-04 18:12:15.198: D/TCPSockets(10875): Created reader/writer
02-04 18:12:15.198: D/TCPSockets(10875): Sent message
02-04 18:12:15.218: D/TCPSockets(10875): 6
02-04 18:12:16.218: E/dalvikvm(10875): JNI ERROR (app bug): attempt to use stale local reference 0x1
02-04 18:12:16.218: E/dalvikvm(10875): VM aborting
02-04 18:12:16.218: A/libc(10875): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1)

返信の読み取りを削除すると、コードは正常に機能します。私を助けてください:(ありがとう

4

0 に答える 0