File indexing completed on 2024-04-28 15:14:08

0001 #!/usr/bin/python
0002 
0003 import socket, psutil
0004 
0005 HOST = 'localhost'
0006 PORT = 1027
0007 ADDR = (HOST,PORT)
0008 serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
0009 
0010 serv.bind(ADDR)
0011 serv.listen(1)
0012 
0013 print 'listening ...'
0014 
0015 while True:
0016   conn, addr = serv.accept()
0017   print 'client connected ... ', addr
0018   cpu_percent = str(psutil.cpu_percent())
0019   conn.send(cpu_percent)
0020   print 'written ' + cpu_percent
0021   conn.close()
0022   print 'client disconnected'