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
© 版权声明
文章版权归作者所有,未经允许请勿转载。

不错,不错。感谢感谢。