简体   繁体   English

可以使用从远程主机连接的 Java 代理来传递数据吗?

[英]Can a java agent attached from a remote host be used to pass data?

I've seen examples like this where an agent can be attach to a running java process using Byte Buddy.我见过这样的例子,其中可以使用 Byte Buddy 将代理附加到正在运行的 Java 进程。

 public static void premain(String args, Instrumentation instrumentation) {

        File file ;
        try {
                file = (new File("BBAgent.jar"));
                ByteBuddyAgent.attach(file,"21345");
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }

// Code to access objects in the original running process here.

    }
}

My question is, would it possible to access the the objects in the original process by adding additional code below the attachment?我的问题是,是否可以通过在附件下方添加附加代码来访问原始进程中的对象? Or does any code that access the data in the original process have to already be packaged in the jar file attachment?还是原进程中访问数据的任何代码必须已经打包在jar文件附件中?

No, objects cannot be transfered from one Java process to another without serializing them.不,对象不能在没有序列化的情况下从一个 Java 进程转移到另一个进程。 You would for example needs to open a socket to transfer bytes from one process to the other where you certainly could send serialized objects.例如,您需要打开一个套接字以将字节从一个进程传输到另一个进程,您当然可以在其中发送序列化对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM