How to send a class through a TCP connection?

I am trying to send a class over a TCP connection using java. When the client receives the class, it must call the methods of this class and return the result to the server.

I serialize the class to an array of bytes to send to the client, but I do not know as soon as the client receives it.

Thank.

+3
source share
3 answers

Your question is a bit ambiguous. Are you sending a file *.classor class instance ? I bet you really mean an instance of the class, as you literally said you want to send it back. This only makes sense if it was a case. The other side should also have a class file in its class path. Then you can just importclass and apply the class to readObject()the desired class. Finally, you can call methods on it in accordance with the class contract.

See also:


If you really send the file *.class, using ClassLoaderto download it will really be the answer.

+3
source
+1

, RMI, .

+1
source

Source: https://habr.com/ru/post/1757229/


All Articles