python对接easyswoole/rpc=5.x

PHP服务端与客户端代码在这:
https://www.jianshu.com/p/7751b843917f

python代码如下:

host =  127.0.0.1 
port = 9600  # initiate port no above 1024

client_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)  # get instance
# look closely. The bind() function takes tuple as argument
client_socket.connect((host, port))  # bind host address and port together
d =  {"service":"BaseAdmin","module":"AdminModule","action":"list","arg":["a","b","c"]} 
head = struct.pack( >I , len(d))
da = head.decode() + d

client_socket.send(da.encode())  # send message
data = client_socket.recv(1024)  # receive response
l = struct.unpack( >I , data[0:4])
j = data[4:]
if(l[0] < 0 && len(j) > l[0]) {
    #返回错误
}
print(j.decode(),l[0],len(j))  # show in terminal

client_socket.close()  # close the connection

© 版权声明

相关文章

1 条评论

  • 头像
    顺直恋 读者

    不错,不错。感谢感谢。

    无记录
    回复