File: server_cpu_udp_socket.py

package info (click to toggle)
labplot 2.12.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 78,528 kB
  • sloc: cpp: 241,047; ansic: 6,324; python: 915; xml: 400; yacc: 237; sh: 221; awk: 35; makefile: 11
file content (16 lines) | stat: -rwxr-xr-x 376 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/python3

from socket import *
import psutil, time

HOST = 'localhost'
PORT = 1027
ADDR = (HOST,PORT)

serv = socket(AF_INET, SOCK_DGRAM)
serv.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
while True:
  message = str(psutil.cpu_percent()) + " " + str(psutil.cpu_freq().current) +  "\n"
  serv.sendto(message.encode(), ADDR)
  print('written ' + message)
  time.sleep(0.5)