#!/usr/bin/env python
import commands
import time
import SocketServer
class MyTCPHandler(SocketServer.BaseRequestHandler):
def handle(self):
print 'Got anew connection from',self.client_address
while True:
cmd = self.request.recv(1024).strip()
if not cmd:
print 'Lostconnection with',self.client_address
break
print'recv:',cmd
#print"{}wrote:".format(self.client_address[0])
#printself.data
cmd_result =commands.getstatusoutput(cmd)
#send resultsize
self.request.send(str(len(cmd_result[1])))
time.sleep(0.2)
#send result
self.request.send(cmd_result[1])
if __name__ == "__main__":
HOST,PORT="192.168.2.110",90
server =SocketServer.ThreadingTCPServer((HOST,PORT),MyTCPHandler)
server.serve_forever()