Aug-07-2017, 06:15 PM
(Aug-07-2017, 10:36 AM)DeaD_EyE Wrote: You can use on sender side io.BytesIO, which behaves like a file.
Then just read with the given buffer size of 1024 for example and
if the length is > 0, then send it. Otherwise break out of the while True loop.
import io # your code # sock = socket.socket() # sock.connect(('ip', port)) data_to_send = b'Foo' * 2000 # we must send bytes print('Data to send:', len(data_to_send)) data = io.BytesIO(data_to_send) while True: chunk = data.read(1024) if not chunk: break sock.send(chunk)What you do before and after this loop, is your responsibility. Maybe you've a protocol to tell the receiver side how much data you are going to send. Maybe you can use a sentinel to tell the receiver side, when the transfer has been finished. Socket programming is not easy.
Thank you for your response!
I guess I should clarify a little bit. I have already successfully been able to transfer a file across the socket connection by reading the the file in bytes and then transferring in way such as you mentioned above.
However, per the instructions I'm supposed to pickle the file and then send it. I have tried opening a file, pickling it, and then sending it in chucks, but it is not working the same. I can not find a single simple example of what I'm trying to do, though I know it's possible. Any thoughts?