I am working a new command line tool https://github.com/a7i7/HoldMyFile . But I am facing some problem with the following function:
def netcat(hostname, port, content):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((hostname, port))
s.sendall(content)
s.shutdown(socket.SHUT_WR)
response = ''
while 1:
data = s.recv(1024)
if data == "":
break
data = repr(data)
response = response + data
s.close()
response = response[:-3][1:]
return response
Whenever I call netcat('termbin.com',9999,content) and content has around 1 MB of data in it, the code exits with the following error message "socket.error: [Errno 32] Broken pipe" .
Now if I send 1 MB of data from the linux shell using
cat data.txt | nc termbin.com 9999
all the data is successfully sent.
I even tried running the same command from the linux shell using os.system from python. still the broken pipe error is encountered. Kindly help me fix this