Skip to content

Commit

Permalink
"Support retrieving files larger than a few KB, requiring multiple ca…
Browse files Browse the repository at this point in the history
…lls to your socket’s send() method"

also fixed the issue with not closing
  • Loading branch information
stacybird committed Jun 8, 2013
1 parent c4268bd commit 088c075
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions project3/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
def start_server(port):
TCP_IP = '127.0.0.1'
BUFFER_SIZE = 1024
flag = True

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, port))
Expand All @@ -35,7 +36,7 @@ def start_server(port):
#this section in a loop so you don't close early.
conn, addr = s.accept()
print 'Connection address:', addr
while 1:
while flag:
# get the request in
data = conn.recv(BUFFER_SIZE)
if not data: break
Expand All @@ -47,7 +48,9 @@ def start_server(port):
print "Response sent: %s" % response
# send the response
conn.send(response) # echo
return conn
conn.close()
flag = False
# return conn



Expand Down Expand Up @@ -119,7 +122,7 @@ def create_response(file_requested):
s = start_server(port)

# won't want to close til you're done.
s.close()
# s.close()

# easier to program it like this, but multi-threading not so much.
# multi-processing works better, but we don't have to.

0 comments on commit 088c075

Please sign in to comment.