Python TCP Socket Transport server Resource information (c/s)

Source: Internet
Author: User

Server-side script:

1 #!/usr/bin/env python2 #Coding:utf83  fromSocketImport*4 ImportOS5 Import time6host="'7port=215678bufsiz=10249Addr=(host,port)Ten  oneTcpsersock =Socket (af_inet,sock_stream) aTcpsersock.bind (ADDR)#Creating Sockets -Tcpsersock.listen (5)#Number of connections -Dic={} the  whileTrue: -tcpclisock, addr = tcpsersock.accept ()#Accept client Connections -data = Tcpclisock.recv (bufsiz)#receiving client Data -Tcpclisock.close ()#shutting down the client +dic[addr[0]]=Data.split () -Os.system ('Touch System_info') +string="' a      forKinchdic: ats = k +' '+ dic[k][0] +' '+ dic[k][1] +' '+dic[k][2] -string+=','. Join (s.split ()) +'\ n'       #Convert a string to a comma by a hollow lattice -With open ('System_info','W') as F: -F.write (string)

Client Script:

1 #!/usr/bin/env python2 #Coding:utf83  fromSocketImport*4 ImportOS5  fromTimeImportSleep6host='192.168.1.226'7port=215678bufsiz=10249Addr=(host,port)Ten              one  whileTrue: aTcpclisock =Socket (af_inet, Sock_stream) -Tcpclisock.connect (ADDR)#try to connect -      whileTrue: thedata = Os.popen ("free-h | head-2 | tail-1 | awk ' {print $2,$3} '"). Read (). strip ('\ n') + -         ' '+ Os.popen ("Vmstat | tail-1 | awk-f "' {print $} '"). Read (). strip ('\ n') -         PrintData -Tcpclisock.send (data)#Send Message +          break -Tcpclisock.close ()#Close Client Connections +Sleep (5)

The server end of the implementation of the Client's ip, total memory, using memory, the CPU is written into the text in a string.

Cases:

192.168.1.121,15g,3.1g,100
192.168.1.42,125g,7.3g,100
192.168.1.43,125g,2.2g,100

Python TCP Socket Transport server Resource information (c/s)

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.