[Python Study Notes] CS Architecture Remote Access get information--client End v1.0

Source: Internet
Author: User

Tag: ISP 1.0 cannot connect decimal usr sel delete style ber

Update content:

1. Add entry bar default IP and port port

2. Fixed Exit function

3. Add Exit Auto Close window function

4. Optimize CPU display as fixed reserved two decimal places

"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "", "" "". "" "" "" "" "" "" "" "," "" "" "," "" "" "," "" "," "" ">> Ps_client.py>> Author: Liu Yang>> e-mail: [email protected] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "." "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" #!/usr/bin/env python#-*-coding:utf-8-*-import sys, osfrom, "" ".        Socket import *from tkinter import *class ps_client (): Def __init__ (self): Self.ip=none Self.port=none Self.data=none # Create IPv4 socket Self.client=socket (af_inet,sock_stream) self.root=tk () self.ro Ot.geometry (' 300x300+250+250 ') # Create 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 () # Create the label Self.ip_lable=labe of the IP input box L (self.root,text= "IP Address") # Create port number input Box Var_port = Stringvar () var_port.set (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, NOTE!!! command= Self.connbutten=button (self.root,text= "Connect", Command=self.connect) # Creates a Get button on the back of the connection Self.get Cpubutten=button (self.root,text= "CPU", state= ' disable ', command=self.get_cpu_info) # Create Disconnect button Self.exitbutten=bu Tton (self.root,text= "Exit", state= ' disable ', Command=self.exit_connect) Self.txtbox=text (self.root,width=40,height= 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.getCpuButten.place (x =90,y=80) Self.exitButten.place (x=180,y=80) self.txtBox.place (x=5,y=120) self.txtBox.insert (INSERT, ' in Show content here ') Self.root.mainloop () def Connect (self): Self.ip=self.et_ip.get () Try:self.por T=int (Self.et_port.get ()) except Valueerror:selF.txtbox.delete (0.0,end) self.txtBox.insert (0.0, "Please enter a valid 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, "in Link:            .") Try:self.client.connect ((self.ip,self.port)) except Oserror:print ("attempts to connect to an unreachable network A socket operation ") Self.txtBox.delete (0.0, END) self.txtBox.insert (0.0,"%s:%d connection failed ... "% (self.ip,self                . Port) Else:print ("%s connection succeeded ..."%self.ip) self.txtBox.delete (0.0, END) Self.txtBox.insert (0.0, "%s:%d connected successfully ..."% (Self.ip,self.port)) # The connection is successful and the other button is changed to a state self.exit butten[' state ']= ' active ' self.getcpubutten[' state ']= ' active ' def get_cpu_info (self): Self.data= ' C Pu ' self.client.send (self.data.encode (' Utf-8 ')) # Replace the accepted data with floating-point data cpu_used=float (SELF.CLIENT.RECV (1024) . Decode (' UTf-8 ') print (' CPU usage:%0.2f '%cpu_used+ '% ') self.txtBox.delete (0.0, END) # string preceded by R for anti-escape self.txt Box.insert (0.0, "Current CPU Usage:%0.2f"%cpu_used+r "%") def exit_connect (self): Self.client.close () Self.txtbox.  Delete (0.0, END) self.txtBox.insert (0.0, "Current connection is broken ...") print ("Current connection is disconnected ...") self.exitbutten[' state ' = ' Disable ' self.getcpubutten[' state '] = ' Disable ' # Close the current window Self.root.destroy () if __name__ = = ' __main_ _ ': Ps=ps_client () Ps.main ()

[Python Study notes]cs schema remote access get information--client End v1.0

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.