我试图将图像从我的服务器发送到我的客户端。
import socket
from PIL import ImageGrab
SERVER_PORT = 80
SERVER_SOCKET = socket.socket()
SERVER_SOCKET.bind((socket.gethostname(),SERVER_PORT))
SERVER_SOCKET.listen(2)
clientname , clientadress = SERVER_SOCKET.accept()
img = ImageGrab.grab()
data = img.tobytes()
clientname.send(data)
clientname.close()
SERVER_SOCKET.close()
然后我尝试将图像从服务器传送到客户端:
import socket
from PIL import ImageGrab
from PIL import Image
my_socket = socket.socket()
my_socket.connect((socket.gethostname(),80))
data = my_socket.recv(4000)
data_img = Image.frombytes(data)
print(data)
它没有用。
有什么想法吗?