Advertisement
rfmonk

zlib_client_broken.py

Jan 30th, 2014
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. # Connect to the server as a client
  2.  
  3.  
  4. import zlib
  5. import logging
  6. import SocketServer
  7. import binascii
  8.  
  9. logger.info('Contacting server on %s:%s', ip, port)
  10. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  11. s.connect((ip, port))
  12.  
  13. # Ask for a file
  14. requested_file = 'lorem.txt'
  15. logger.debug('sending filename: "%s"', requested_file)
  16. len_sent = s.send(requested_file)
  17. # Receive a response
  18. buffer = StringIO()
  19. decompressor = zlib.decompressobj()
  20. while True:
  21.     response = s.recv(BLOCK_SIZE)
  22.     if not response:
  23.         break
  24.     logger.debug('READ "%s"', binascii.hexlify(response))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement