[Tutor] Sending Pickled Data from Server to Client via Sockets

Christian Liz-Fonts christian.lfonts at gmail.com
Mon Apr 13 12:25:31 EDT 2020


I first tried

message = pickle.dumps(s2)
cs.sendall(message)

on my server and for my client

msg = ns.recv(32,768)

this returned

msg = ns.recv(32,768) OSError: [WinError 10045] The attempted operation is
not supported for the type of object referenced


So I then tried, my server being


HL = 10
...

message = pickle.dumps(s2)

message_header - bytes(f"{len(message):<{HL}}", "utf-8")+messae

cs.send(message_header + message)

and this being my client

while True:
    full_msg = b''
    new_msg = True
    while True:
         msg = ns.recv(16)
         if new_msg:
             print("new msg len:", msg[:HL])
             msglen = int(msg[:HL])
             new_msg = False
         print(f"full message length: {msglen}")
         full_msg += msg
         print("adding other parts together")
         print(len(full_msg))
         if len(full_msg)-HL == msglen:
             new_msg = True
             full_msg = b""
             print("full msg recvd") print(full_msg[HL:])


this returned

new msg len: b'5575 '

then it printed out

full message length: 5575
adding other parts together
16

until reaching

full message length: 5575
adding other parts together
11160

as you can imagine my log is a bit lengthy as it is going up by 16 bytes
each time. Also it seems as if the last is statement does not run

if len(full_msg)-HL == msglen:

I imagine this is because len(full_msg)-HL is exceeding msglen?

what should I do was the first direction I was heading in the correct one
or the second? I am sending and receiving files between my own clients to
my host so no other person will be sending data to me so it does not need
to be secure, I just need to most efficient method to do what I need to do
have been trying to correct this error for 36 hours and decided to give
this a try. Please advice me on how to proceed.


More information about the Tutor mailing list