本文共 1293 字,大约阅读时间需要 4 分钟。
分类: 2011-12-05 18:18 382人阅读 -
- ''
-
-
-
-
-
- import socket
- import sys
- import time
- if __name__=='__main__':
-
- try :
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- except socket.eorror,e:
- print 'socket false:%s'%e
- print 'socket ...'
-
-
- try :
- sock.connect(('220.181.111.148',80))
- except socket.error,e:
- print 'connect false %s'%e
- sock.close()
- print 'connect ...'
-
-
- try :
- print 'send start...'
- str='GET / HTTP/1.1\r\nHost:www.baidu.com\r\nConnection:keep-alive\r\n\r\n'
- sock.send(str)
- except socket.eorror,e:
- print 'send false'
- sock.close()
-
- data=''
- data = sock.recv(1024)
- while (1): ''
-
-
-
-
- print data
- beg = data.find('Content-Length:',0,len(data))
- end = data.find('Content-Type:',0,len(data))
- print beg
- print end
- if(beg == end):
- print 'connecting closed'
- break
- num = long(data[beg+16:end-2])
- print num
- nums = 0
- while (1):
- data=sock.recv(1024)
- print data
- nums +=len(data)
- if(nums >= num):
- break
- word = raw_input('please input your word----->')
- str='' + word + ''
-
-
-
-
- print str
- sock.send(str)
- data = ''
- data = sock.recv(1024)
- sock.close()
- print data
转载地址:http://vzmbx.baihongyu.com/