So a snippet my attempted pickling server code:
I'm new to Python and network programming, so it's a double whammy. Thanks for any help.
Another thought. Let's assume the following:
Can someone give me basic code to send the pickled file (in chunks of 1024 bytes) over a socket connection and then basic code to receive the pickled file (in chunks of 1024 bytes) and then unpickle it?
Then I can see how it's done and modify my code to work.
i think some of the confusion for me is that I was told it is easier to pickle file and then send it as opposed to other options. Though in my original code I just read the file as binary and then sent it in chucks and had no problem.
Thanks.
with open(file_requested, 'rb') as temp: f = temp.read() f = dumps(f) # DOESN'T WORK - CAN'T READ segment = f.read(BUFFER) self.connection_socket.send(segment) print('Sending file....') # Run while segment has binary data while segment: # DOESN'T WORK - CAN'T READ segment = f.read(BUFFER) self.connection_socket.send(segment)A snippet my attempted pickling client code:
f = open('new_' + requested_file, 'wb') segment = client_socket.recv(BUFFER) # Keep track of the current size of the file as it's downloaded current_file_size = len(segment) # Start creating the file with the current segment f.write(segment) # Run until the file is downloaded while current_file_size < file_size: segment = client_socket.recv(BUFFER) current_file_size += len(segment) f.write(segment) # THEN UNPICKLE FILESo, I know that I can read the parts of the pickled file as it gives me an error. Which means I have to break the file up some other way. Then, I know that my client needs to read each segment differently (maybe as a byte string) and then somehow I need to unpickle the completed file.
I'm new to Python and network programming, so it's a double whammy. Thanks for any help.
Another thought. Let's assume the following:
- I have successfully grabbed a file (image, pdf, etc) of 10000 bytes from a directory
- I then pickled the file (we will call it pickledFile)
Can someone give me basic code to send the pickled file (in chunks of 1024 bytes) over a socket connection and then basic code to receive the pickled file (in chunks of 1024 bytes) and then unpickle it?
Then I can see how it's done and modify my code to work.
i think some of the confusion for me is that I was told it is easier to pickle file and then send it as opposed to other options. Though in my original code I just read the file as binary and then sent it in chucks and had no problem.
Thanks.