2

I have two machines using python rpyc ,one is server(ip:10.0.3.120), another is client(ip:10.0.3.197). The code shows below:

Server (ip:10.0.3.120)

from rpyc import Service
from rpyc.utils.server import ThreadedServer

class TestService(Service):

    def exposed_test(self, num):
        return num + 1

sr = ThreadedServer(TestService, port=9999, auto_register=False)
sr.start()

Client (ip:10.0.3.129)

import rpyc
conn = rpyc.connect('10.0.3.120', 9999)
cResult = conn.root.test(11)
conn.close()

print cResult

Client shows this error when I run server and client:

Traceback (most recent call last):
File "rpyc_client.py", line 4, in <module>
conn = rpyc.connect('10.0.3.120', 9999)
File "/usr/local/lib/python2.7/site-packages/rpyc-3.2.3-py2.7.egg/rpyc/utils/factory.py", line 89, in connect
s = SocketStream.connect(host, port, ipv6 = ipv6)
File "/usr/local/lib/python2.7/site-packages/rpyc-3.2.3-py2.7.egg/rpyc/core/stream.py", line 114, in connect
return cls(cls._connect(host, port, **kwargs))
File "/usr/local/lib/python2.7/site-packages/rpyc-3.2.3-py2.7.egg/rpyc/core/stream.py", line 92, in _connect
s.connect((host, port))
File "/usr/local/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)

How does connect method use? If I use public network IP to build a rpyc server, could I connect it at home ?? Thanks a lot!

changzhi
  • 2,641
  • 9
  • 36
  • 46

2 Answers2

1

First, check for a connection command ping. In your code server runs at localhost. In order so that it can be accessed from outside your correct address or * (then the server will run on all possible addresses of the current machine). I think auto_register must be equal to None.

from rpyc import Service
from rpyc.utils.server import ThreadedServer

class TestService(Service):

    def exposed_test(self, num):
        return num + 1

sr = ThreadedServer(TestService, hostname='10.0.3.120', port=9999, auto_register=None)
# or sr = ThreadedServer(TestService, hostname='*', port=9999, auto_register=None)
sr.start()
1

Just delete all iptables rules on the client with this command:

iptables -F
peak
  • 105,803
  • 17
  • 152
  • 177
Ian
  • 23
  • 6
  • Why do you think that will help? Also, you risk throwing away a lot of network protections without really knowing how this will help. – jeteon May 09 '16 at 16:16
  • This workaround assumes your machine on intranet but not in internet, it might encounter lots of network threats as you emphasized while you are in a real open network environment. – Ian May 12 '16 at 05:27
  • I understand. I was just suggesting that you add an explanation of why you think the iptables command will help solve the problem for someone who might not be as familiar with iptables as you are. Also, it would be a good idea to add the sentence in your comment as a disclaimer to the original answer. Basically, if you edit your answer and add this information, you might have better success with it. – jeteon May 12 '16 at 06:31