忘了在那转的,有人知道的话,告诉我一下,今天在服务器里拿出来,感觉挺好玩的,就放上来了
server.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import SocketServer
import os
import threading
class MyHandle(SocketServer.StreamRequestHandler):
def handle(self):
self.data = self.rfile.readline().strip()
print "%s wrote:" % self.client_address[0]
print self.data
self.datas=os.popen(self.data).read()
self.wfile.write(self.datas)
if __name__=='__main__':
addr=""
port=9999
server = SocketServer.ThreadingTCPServer((addr, port), MyHandle)
server_thread = threading.Thread(target=server.serve_forever)
server_thread.setDaemon(True)
server_thread.start()
server.serve_forever()
server.shutdown()
client.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from socket import *
HOST='127.0.0.1'
PORT=9999
BUFSIZ = 2048
ADDR = (HOST, PORT)
while True:
tcpCliSock = socket(AF_INET, SOCK_STREAM)
tcpCliSock.connect(ADDR)
data = raw_input('> ')
if not data:
break
tcpCliSock.send('%s\r\n' % data)
data = tcpCliSock.recv(BUFSIZ)
if not data:
break
print data.strip()
tcpCliSock.close()
终于找到从那看来的了,和和,现在补上
阅读(1686) | 评论(1) | 转发(0) |