0 Star 0 Fork 231

rockylee/python-learn

forked from mktime/python-learn 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sock_client.py 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
mr.github 提交于 2015-03-17 11:56 . simple rpc call through tcp socket
import socket, sys, time
def start_chat():
#serv_addr = ('136.24.8.73', 1989)
serv_addr = ('127.0.0.1', 1989)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(serv_addr)
while True:
data = sys.stdin.readline()
s.send(data)
if data.strip() == 'quit':
print "bye!"
time.sleep(1)
break;
data = s.recv(1024)
print data
print "\n$",
time.sleep(1)
s.close()
def simple_call_rpc():
serv_addr = ('136.24.8.45', 1989)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(serv_addr)
program_name = "R2319Cfm"
cmd = "find /crmbak -name %s.log.gz -mtime 30 2>/dev/null |xargs ls -l --block-size=1024 |grep %s.log.gz$ 2>/dev/null |awk '{sum+=$5}END{print sum}'" % (program_name, program_name)
s.send(cmd)
data = s.recv(1024)
print 80 * '-'
print "cmd:", cmd
print "data:", data
print 80 * '-'
s.close()
if __name__ == '__main__':
simple_call_rpc()
#start_chat()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/isliwg/python-learn.git
git@gitee.com:isliwg/python-learn.git
isliwg
python-learn
python-learn
master

搜索帮助