微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我想从vpninterface读取字节,然后再写回去

如何解决我想从vpninterface读取字节,然后再写回去

我已经设置了VPN服务,然后配置了VPN接口。

 private void setupVPN() {
        try {
            if (vpnInterface == null) {
                Builder builder = new Builder();
                builder.addAddress(VPN_ADDRESS,32);
                builder.addRoute(VPN_ROUTE,0);
                builder.setMtu(1499);
                vpnInterface = builder.setSession(getString(R.string.app_name)).setConfigureIntent(pendingIntent).establish();

            }
        } catch (Exception e) {
            Log.e(TAG,"error",e);
            System.exit(0);
        }
    }

我可以从文件描述符中读取字节,但如何将其写回。

 FileChannel vpnInput = new FileInputStream(vpnFileDescriptor).getChannel();
            FileChannel vpnOutput = new FileOutputStream(vpnFileDescriptor).getChannel();
            Thread t = new Thread(new WriteVpnThread(vpnOutput,networkToDeviceQueue));
            t.start();

            try {
                ByteBuffer bufferToNetwork = null;
                while (!Thread.interrupted()) {
                    bufferToNetwork = ByteBufferPool.acquire();
                    int readBytes = vpnInput.read(bufferToNetwork);
                    if (readBytes > 0) {

                       bufferToNetwork.flip();
                    }
                }
            }

我必须先解析它们,然后再写回去吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。