-3

I'm currently writting a TCP/IP client in Java. The only thing that the client should be able to do is to run code that the server sends to it. I have seen this question , but my problem is that the code would be ran like if it was another application, but if the client code contains a string and the server sends a message saying, read the string and send back the content, then the client would not be able to do so because that code would be executed in another program where that string dosen't exist :-(

So is there a way that i can run code from a input like if it was written in the source code of the program?

All help is much appreciated :-)

Example:

The client contains a string that says "string0001". The client should run the code that the server sends. The server sends a block of java-code that the client shouls be able to execute. The code says: check content of string and send it back to this ip. The client should now be able to read the string and send back "string0001" to the servers ip.

With the solution that the link provided, the code that the server sent would be executed like if it was another program, and in that program the string that the server requested the client to read does not exist.

The client whould now be able to run the code like if it was written in the clients source, where the string exist.

Hope that helps :-)

4

1 回答 1

0

那么第一个问题是发送的源代码必须是完整的。Java 是一种面向对象的语言,因此要执行的代码可能会引用尚未发送的类。

这导致了第二个问题......它如何知道它何时收到了所有代码,以及代码需要保存在哪些包和文件中?

如果代码是一个非常简单的例程,没有方法或类,您可以创建一个具有方法的类并将传递的代码插入其中,然后将其保存在内存中。

然后,您可以使用与此处回答的问题类似的例程来编译此代码。

于 2013-02-11T00:12:30.010 回答