截图,用python编写socket发送

2024-09-19 23:34:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从服务器截图并通过套接字发送到客户端,
在客户端接收并显示(作为视频)

我试试这个:

在服务器中

from PIL import ImageGrab
import base64
from io import StringIO,BytesIO
def sendVideo(MySocket):
    print("in sendVideo")
    buffer = BytesIO()
    while True:
        im = ImageGrab.grab()
        im.save(buffer, format='PNG')
        b64_str = base64.b64encode(buffer.getvalue())
        MySocket.send(b64_str)  

在客户端

^{pr2}$

但不能正常工作(这意味着它只发送一个图像(第一帧),并且只显示相同的图像)

我使用pythonv3.7

谢谢你


Tags: from图像import服务器客户端视频bufferbase64