Created
September 25, 2017 16:31
-
-
Save stefanoschrs/903cea4ad85711c9998be32efd31e189 to your computer and use it in GitHub Desktop.
Get files through TCP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import time | |
import os | |
s = socket.socket() | |
host = socket.gethostname() | |
port = os.getenv('PORT') if 'PORT' in os.environ else '8080' | |
print 'Starting Receiver on %s:%s' % (host, port) | |
s.bind(('', int(port))) | |
s.listen(5) | |
while True: | |
c, addr = s.accept() | |
print 'Connection open from ', addr | |
filename = '/tmp/receiver-%d' % time.time() | |
f = open(filename, 'wb') | |
print 'Writing results to %s' % filename | |
packet = c.recv(1024) | |
while (packet): | |
f.write(packet) | |
packet = c.recv(1024) | |
f.close() | |
print 'Done' | |
c.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment