'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
>> file : ps_client.py
>> author : liu yang
>> mailbox : liuyang0001@outlook.com
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os
from socket import *
from tkinter import *
class Ps_client():
def __init__(self):
self.ip=None
self.port=None
self.data=None
# establish ipv4 Socket
self.client=socket(AF_INET,SOCK_STREAM)
self.root=Tk()
self.root.geometry('300x300+250+250')
# establish IP Input box
var_ip = StringVar()
var_ip.set('localhost')
self.et_ip=Entry(self.root,width=30,textvariable=var_ip)
self.et_ip.pack()
# establish IP Input box Label
self.ip_lable=Label(self.root,text="ip Address ")
# Create a port number input box
var_port = StringVar()
var_port.set(66)
self.et_port=Entry(self.root,width=30,textvariable=var_port)
# Create port number Label
self.port_lable=Label(self.root,text=" Port number ")
# Create connection button , Be careful !!!command= The following connection is not bracketed
self.connButten=Button(self.root,text=" Connect ",command=self.connect)
# Create get button
self.getButten=Button(self.root,text=" obtain ",state='disable',command=self.get_cpu_info)
# Create the disconnect button
self.exitButten=Button(self.root,text=" sign out ",state='disable')
self.txtBox=Text(self.root,width=40,height=10)
def main(self):
self.et_ip.place(x=5,y=20)
self.et_port.place(x=5,y=50)
self.ip_lable.place(x=230,y=20)
self.port_lable.place(x=230,y=50)
self.connButten.place(x=5,y=80)
self.getButten.place(x=90,y=80)
self.exitButten.place(x=180,y=80)
self.txtBox.place(x=5,y=120)
self.txtBox.insert(INSERT,' Show the content here ')
self.root.mainloop()
def connect(self):
self.ip=self.et_ip.get()
try:
self.port=int(self.et_port.get())
except ValueError:
self.txtBox.delete(0.0,END)
self.txtBox.insert(0.0," Please enter legal ip And port ...")
else:
print("ip:%s"%self.ip)
print("port:%s"%self.port)
self.txtBox.delete(0.0,END)
self.txtBox.insert(0.0," Linking ...")
try:
self.client.connect((self.ip,self.port))
except OSError:
print(" A socket operation was attempted to an unreachable network ")
self.txtBox.delete(0.0, END)
self.txtBox.insert(0.0, "%s:%d The connection fails ..."%(self.ip,self.port))
else:
print("%s Successful connection ..."%self.ip)
self.txtBox.delete(0.0, END)
self.txtBox.insert(0.0, "%s:%d Successful connection ..."%(self.ip,self.port))
# If the connection is successful, other buttons can be pressed
self.exitButten['state']='active'
self.getButten['state']='active'
def get_cpu_info(self):
self.data='cpu'
self.client.send(self.data.encode('utf-8'))
cpu_used=self.client.recv(1024).decode('utf-8')
print(cpu_used)
self.txtBox.delete(0.0, END)
# The string is preceded by r In case of escape
self.txtBox.insert(0.0, " Current cpu Usage rate :%s"%cpu_used+r"%")
def exit_connect(self):
self.client.close()
self.txtBox.delete(0.0, END)
self.txtBox.insert(0.0, " The current connection has been disconnected ...")
if __name__ == '__main__':
Ps=Ps_client()
Ps.main()

[Python Study Notes]CS Architecture remote access to get information --Client More related articles on the Internet

  1. [Python Study Notes]CS Architecture remote access to get information --Client End v2.0

    Update the content : 1. Increase memory information acquisition 2. Increase battery information access 3. Increase access to disk information 4. Rearrange the form 5. Add form name 6. Before the connection is successful , Do not press design sketch : '''''''''''''''''''''' ...

  2. [Python Study Notes]CS Architecture remote access to get information --Client End v1.0

    Update the content : 1. add to entry Column default ip and port mouth 2. Fixed exit function 3. Add exit auto close window function 4. Optimize cpu The display is fixed to two decimal places '''''''''''''''''''''''''''''' ...

  3. [Python Study Notes]CS Architecture remote access to get information --SERVER End v2.0

    Update the content : 1. Increase memory information acquisition 2. Increase battery information access 3. Increase access to disk information 4. Rearrange the form 5. Add form name 6. Before the connection is successful , Do not press ''''''''''''''''''''''''''' ...

  4. [Python Study Notes]CS Architecture remote access to get information --SERVER End

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  5. Eureka series ( 3、 ... and ) Access to services Client The specific implementation of the end

    Access to services Client End process Let's take a look at the picture below , This picture briefly describes us Client How to get Server Process of renewed instance information : From the picture we can see that the general process is Client I'll open one myself ...

  6. [Python Study Notes] Process information ( Dingding software monitors the process ,http-post)

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  7. [Python Study Notes]cpu Information

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  8. [Python Study Notes] Battery information

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  9. [Python Study Notes] Memory information

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

Random recommendation

  1. div+css:div Center the picture vertically

    div Center the picture vertically <!DOCTYPE html> <html> <head> <meta charset="utf-8"> &l ...

  2. CSS3 Realize yin yang fish

    Go straight to the code : <!doctype html> <html> <head> <meta charset="utf-8" /> < ...

  3. 【CodeForces 567E】President and Roads( shortest path )

    Description Berland has n cities, the capital is located in city s, and the historic home town of th ...

  4. Remember a Web Performance tuning of services

    Preface A project is going through development . test . After the launch , At that time, the scale of users was relatively small , So the projects just launched will generally perform stably . But over time , The increase in the number of users ,qps The increase in the number of users and other factors will cause the project to slowly show that the web page has no response for half a day . Before ...

  5. UnityShader The fixed pipeline command Combine Texture blending 【Shader Information 4】

    Combine, Texture blending . Let's first look at the explanation given in the Scripture . Texture is applied after the basic vertex illumination is calculated . In the shader, through SetTexture Order to complete . SetTexture The command does not take effect when the program is used : This kind of model ...

  6. difference between instance variable and property

    @interface MyClass : NSObject { NSString *name; NSArray *items; Something *something; IBOutlet NSTex ...

  7. Learn from the beginning JavaScript ( 6、 ... and )—— sentence

    original text : Learn from the beginning JavaScript ( 6、 ... and )-- sentence One . Conditional branch statement :if The basic format : if (< expression 1>){    < Statement group 1>}else if (< expression 2> ...

  8. netty The benefits of

    netty As a high performance asynchronous communication framework , What are the benefits of it , What basic technologies are used ? 1. Use ServerBootstrap As netty Server side startup assistant class , And creating ServerBootstrap when ...

  9. springboot Service Engineering , Front end service call interface reported cross domain error

    Fore and aft end separation ,VUE.JS When calling the service interface , Cross domain error . Need service interface engineering settings , as follows : @SpringBootApplicationpublic class SpringCloudOpenapiApplica ...

  10. A topological sort bfs_dfs

    dfs #include <cstdio> #include <cstring> using namespace std; ; struct Edge{ int lst; in ...