在python中共享屏幕

时间:2018-03-25 00:08:36

标签: python pygame

我正在尝试在python 2.7中创建一个屏幕共享程序。

两个用户通过套接字连接在一起。用户1将与用户2共享他的屏幕。我无法找到一种更有效的分享方式,而不仅仅是发送大量图片。

您对如何改进我的代码有任何想法吗?

客户:(获取图片)

def room_client(port,ip):
roomC = socket.socket()
roomC.connect((ip, port))


while True:

    while 1:
        data = roomC.recv(4096)

        split_msg = data.split('@!!@')
        print split_msg
        filesize = long(split_msg[1])
        roomC.send('got!')
        data = roomC.recv(4096)
        totalRecv = len(data)
        print filesize
        mon = open('new_monitor.png', 'wb')
        mon.write(data)
        while totalRecv < filesize:
            data = roomC.recv(4096)
            totalRecv+=len(data)
            mon.write(data)

        mon.close()
        blit_image(mon) # blitting the image (pygame)

服务器:(发送图片)

def room_server(port):
    roomS = socket.socket()
    roomS.bind(('0.0.0.0',port))
    roomS.listen(1)

    client, addr = roomS.accept()

    while True:
      while 1:
        with mss() as sct:
            sct.shot()
            with open('monitor-1.png', 'rb') as pic:
                to_send = pic.read(4096)
                size = os.path.getsize('monitor-1.png')
                client.send("size@!!@"+str(size))
                print client.recv(4)
                client.send(to_send)
                while to_send != "":
                    to_send = pic.read(4096)
                    client.send(to_send)
                pic.close()

0 个答案:

没有答案