1 #!/usr/bin/python 2 #coding=utf-8 3 #服务器端 4 from socket import * 5 from time import ctime 6 7 HOST="192.168.1.33" 8 ADDR=1234 9 t=(HOST,ADDR) 10 11 sockob=socket(AF_INET,SOCK_STREAM) 12 sockob.bind((HOST,ADDR)) 13 sockob.listen(3) 14 print "starting listen....." 15 while 1: 16 a,b=sockob.accept() 17 print "connet from :",b 18 while 1: 19 data=a.recv(1024) 20 if not data: 21 break 22 a.send("[%s]:%s"%(ctime(),data)) 23 sockob.close() 24 a.close()
1 #!/usr/bin/python 2 #coding=utf-8 3 #客户端 4 from socket import * 5 import sys 6 HOST=sys.argv[1] 7 PORT=int(sys.argv[2]) 8 BUFSIZE=1024 9 ADDR=(HOST,PORT) 10 sockob=socket(AF_INET,SOCK_STREAM) 11 sockob.connect(ADDR) 12 while 1: 13 data=raw_input(">",) 14 if not data: 15 break 16 sockob.send(data) 17 data=sockob.recv(BUFSIZE) 18 print data 19 sockob.close()
时间: 2024-10-06 22:34:09