0

As explained here, redirecting the stdio/stdin is very simple with RPyC 2. This means that 'print' commands executed in the server, will display the printed string on the client side.

RPyC 2, as explained here, is un-secured and is not recommended, but I couldn't find anywhere how can I print on the client side with RPyC 3.

Does anyone know how to achieve this?

Edit:

For example, this is the code to my server:

import rpyc
import time
from rpyc.utils.server import ThreadedServer

class TimeService(rpyc.Service):
    def exposed_print_time(self):
        for i in xrange(10):
            print time.ctime()
            time.sleep(1)

if __name__ == "__main__":
    t = ThreadedServer(TimeService, port=8000)
    t.start()

and in my client, I run:

conn = rpyc.connect("192.168.1.5")
conn.root.print_time()

my goal is to get the time every second (or anything else I want to print) in the client's stdout, but the client just hangs and the time is only printed in the server.

speller
  • 1,641
  • 2
  • 20
  • 27
  • Did you went through tutorials? Did it work? If not, what went wrong or what you did not understand? – Jan Vlcinsky May 05 '14 at 19:32
  • @Jan Vlcinsky I went through the tutorials and it all worked, but they don't explain how to redirect the output to the client. After completing the tutorials and printing on the server, the print output is shown in the server only, and I want it to show in the client – speller May 05 '14 at 20:22
  • It would be great if you show some code. Do you want to execute something on a client and see it printed on a server? Will anybody have a chance to see such a printout? Or you expect the server to react by some action to it? What action? – Jan Vlcinsky May 05 '14 at 20:26
  • @JanVlcinsky I've edited my server's code to my post – speller May 06 '14 at 05:07
  • wouldn't it be much simpler to do `print conn.root.get_time()` instead? – shx2 May 06 '14 at 18:08
  • @shx2 - I would look like that, yes, but then I'll have to implement some logic in the client side. e.g. in the code above, to do a loop that sleeps and calls get_time() 10 times. I don't want any logic to be on the client side - only to call a function and that the server would do the rest. It's possible in RPyC 2. The question is - is that possible in RPyC 3? – speller May 06 '14 at 20:30

1 Answers1

0

you could use return on server side:

#on server
def exposed_test(self):
   return "this is test"

#on client
conn.root.test()
>>> 'this is test'
ForteD
  • 41
  • 4