通过最简单的一个调用例子:
Server端
from rpyc import Service
from rpyc.utils.server import ThreadedServer
import time
class pc2Service(Service):
def exposed_get_time(self):
now_time = time.time()
print now_time
return now_time
S=ThreadedServer(pc2Service, port=12345)
S.start()
Client端
import rpyc
import time
c=rpyc.connect('192.168.250.20',12345)
for i in range(5):
time.sleep(1.5)
print c.root.get_time()
c.close()
抓包
1、首先通过3次握手建立TCP连接
2、基于建立的TCP连接传输远程调用命令及数据
追踪整个TCP流,只能看到调用了哪些命令,看不到具体传输的数据
......QP.S.Q.
...&..RP.T...34688896.
pc2Service..__main__
......QQ.`.Q...34688896
......RQ.Q. ..
_rpyc_setattr....exposed_get_time...
on_connect.)called when the connection is established..
__format__..default object formatter..
on_disconnect.icalled when the connection had already terminated for cleanup
(must not perform any IO on the connection)...__subclasshook__....3Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__().
It should return True, False or NotImplemented. If it returns
NotImplemented, the normal algorithm is used. Otherwise, it
overrides the normal algorithm (and the outcome is cached)...
_rpyc_getattr...
_rpyc_delattr...
__sizeof__.2__sizeof__() -> size of object in memory, in bytes
......QR.T.Q...34688896..get_time
...-..RR.T...30243976..instancemethod..__builtin__
......QS.W.Q...30243976..
......RS.Q.A..V...o
......QT._.Q...30243976
......RT.Q.
......QU.T.Q...34688896..get_time
...-..RU.T...30225512..instancemethod..__builtin__
......QV.W.Q...30225512..
......RV.Q.A..V.{S.
......QW._.Q...30225512
......RW.Q.
......QX.T.Q...34688896..get_time
...-..RX.T...30243976..instancemethod..__builtin__
......QY.W.Q...30243976..
......RY.Q.A..V....
......QZ._.Q...30243976
......RZ.Q.
......Q[.T.Q...34688896..get_time
...-..R[.T...30225512..instancemethod..__builtin__
......Q\.W.Q...30225512..
......R\.Q.A..V.<.1
......Q]._.Q...30225512
......R].Q.
......Q^.T.Q...34688896..get_time
...-..R^.T...30243976..instancemethod..__builtin__
......Q_.W.Q...30243976..
......R_.Q.A..V..Z.
......Q`._.Q...30243976
......R`.Q.
......Qa.R.Q.
3、通过4次握手关闭连接