File indexing completed on 2024-12-08 03:34:23

0001 #!/usr/bin/python3
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 serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
0010 
0011 serv.bind(ADDR)
0012 serv.listen(1)
0013 
0014 print ('listening ...')
0015 
0016 while True:
0017   conn, addr = serv.accept()
0018   print('client connected ... ', addr)
0019   #message = str(psutil.cpu_percent())
0020   # multiple values
0021   message = str(psutil.cpu_percent()) + " " + str(psutil.boot_time()) + " " + str(psutil.cpu_count())
0022   conn.send(message.encode())
0023   print('written ' + message)
0024   conn.close()
0025   print('client disconnected')