Server
#! /Usr/bin/env python
Import socket
Import time
Host =''
Port = 99999
S = socket. socket (socket. AF_INET, socket. SOCK_STREAM)
S. bind (host, port ))
S. listen (2)
While 1:
Conn, addr = s. accept ()
#---------------
Print 'got connection from: ', addr
While 1:
Data = conn. recv (4096)
Print 'get data', data
If not data: # determine whether a value is accepted
Time. sleep (1, 5)
Continue
Conn. sendall (data. upper ())
Print 'asdfasf', data
Conn. close ()
Client
#! /Usr/bin/env python
Import socket
Import time
H = '1970. 168.5.55'
P = 99999
S = socket. socket (socket. AF_INET, socket. SOCK_STREAM)
S. connect (h, p ))
While 1:
S. send ('Hello word ')
Received_data = s. recv (1024)
Time. sleep (1.5)
Print 'safasfasf', received_data
S. close ()
This article is from the "Monitor hard disk usage" blog, please be sure to keep this source http://5471815.blog.51cto.com/5461815/1300203