#!/usr/bin/python
#coding=utf-8
#服务器端
from socket import *
from time import ctime HOST="192.168.1.33"
ADDR=1234
t=(HOST,ADDR) sockob=socket(AF_INET,SOCK_STREAM)
sockob.bind((HOST,ADDR))
sockob.listen(3)
print "starting listen....."
while 1:
a,b=sockob.accept()
print "connet from :",b
while 1:
data=a.recv(1024)
if not data:
break
a.send("[%s]:%s"%(ctime(),data))
sockob.close()
a.close()
 #!/usr/bin/python
#coding=utf-8
#客户端
from socket import *
import sys
HOST=sys.argv[1]
PORT=int(sys.argv[2])
BUFSIZE=1024
ADDR=(HOST,PORT)
sockob=socket(AF_INET,SOCK_STREAM)
sockob.connect(ADDR)
while 1:
data=raw_input(">",)
if not data:
break
sockob.send(data)
data=sockob.recv(BUFSIZE)
print data
sockob.close()
05-11 15:12