服务端
import socket
import time
def main():
s = socket.socket()
s.bind(("",8081))
s.listen(5)
while(True):
c,addr = s.accept()
print("与"+str(addr)+"建立了连接")
index = 0
while(index<10):
now_time = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
c.send(now_time)
time.sleep(10)
index = index + 1
c.close()
if __name__ == "__main__":
main()
客户端
import socket
s= socket.socket()
s.connect(("192.168.199.221",9000))
while True:
print s.recv(1024)
s.close()