in order to send numpy arrays(images) over socket i used pickle, but sometimes it says "_pickle.UnpicklingError: pickle data was truncated" i found some fixes but they didn't work for one reason: i'm sending array every time possible, because im making a screen-share script, and the solutions were to put a loop that takes parts of the msg and combines them. and since i'm sending the array every while loop run it combines all the arrays together. what can i do?
server:
import cv2
import numpy
import pyautogui
import pickle
import time
import socket
a = pickle.dumps(numpy.array([4556]))
print (a)
b = pickle.loads(a)
print(b)
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((socket.gethostname(), 3948))
server.listen()
client, addres = server.accept()
print("listening")
while True:
screen = pyautogui.screenshot()
cv2thing = numpy.array(screen)
rgb = cv2thing[...,::-1].copy()
client.send(pickle.dumps(rgb))
print("sent")
if cv2.waitKey(1) == ord('q'):
break
client:
import socket
import cv2
import pickle
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((socket.gethostname(), 3948))
print("connected")
while True:
cv2.imshow('frame', pickle.loads(client.recv(999999999)))
if cv2.waitKey(1) == ord('q'):
cv2.destroyAllWindows()
break
sendall(); there's no guaranteesend()sends everything.