python - Issues with sending large JSON file over socket -
i'm @ point in network learning have realized things aren't perfect , network packets can out of sync , might not send in 1 packet.
my program works small data being sent on socket, not large file. keep getting valueerror: expecting ','
or expecting ':'
whenever trying send big file , think it's because receiving function not good. i've read lot on how have implement own protocol reading information socket still have found no information on how implement that.
my program serializes information on computer , sends on json computer. heard somewhere json automatically deals sending packet information or that, i'm not clear meant.
in case, receiving function:
def recieve(node, s, timeout=2): s.setblocking(false) #array of data all_data = [] begin = time.time() while true: #if data received, break after timeout if all_data , time.time()-begin > timeout: break #if no data received @ all, wait more elif time.time() - begin > timeout * 2: break try: data = '' while len(data) < buffer_size: data += s.recv(buffer_size - len(data)) if data: all_data.append(data.decode('utf-8')) #reset begin timeout begin = time.time() except: pass return json.loads(''.join(all_data))
and use `sendall(dumps((data1, data2, data3, data4, data5)).encode()) encode python information (which dictionaries, lists, etc).
i'm not sure if timeouts make sense, i'm complete beginner network programming, , i'm not sure go here. should use socket.makefile()
? still need implement network protocol when using json? how implement network wrapper system if need it?
thanks in advance!
Comments
Post a Comment