Greetings. I am writing a client/server program in python to send a large csv file over the network. The client and server codes are given below.
client.py
import socket
HOST = 'server ip'
PORT = 42050
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
f = open('my.csv', 'rb')
print "Sending Data ...."
l = f.read()
while True:
for line in l:
s.send(line)
break
f.close()
print "Sending Complete"
s.close()
server.py
import socket
HOST = 'local ip'
PORT = 42050
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
print "Server running", HOST, PORT
s.listen(5)
conn, addr = s.accept()
print'Connected by', addr
while True:
data = "".join(iter(lambda:conn.recv(1),"\n"))
print data
if not data: break
print "Done Receiving"
conn.close()
While executing, the server is printing the contents line by line as desired. However, it seems to be stuck in the loop and is not 'breaking' as it should be. I think I'm doing it wrong with the break statement in the server.py.
Thanks for all the help in advance.