Top 5 Scripts 2022: Python Screen Sharing / Screen Mirror

How to Create a Python Screen Sharing App:

Python is a powerful programming language that can be used to create many things. One of the tools that is frequently used in the python language is a screen share or screen mirror.It’s about the software and how to use it. It’s about how to write scripts for the software too.Python is an incredible programming language and there are many ways to use it in some way. Here’s a blog post that discusses one of the many tools built into the Python language: screen share or screen mirror.

Python is a high-level programming language that is used for general-purpose programming. With this tool, you can display your desktop on a external device or website, such as your iPad or Chromebook. However, if you’re using a computer running Ubuntu or Linux, you’ll need to install the Screen Share utility.you can use to share your screen on your computer or phone to make it easier to work with someone else on a computer.

Screen mirroring or screen sharing is a capability of some software that allows you to create a virtual screen where one or both ends can interact with the screen, but one end is not physically there. Screen sharing is mostly used in a business setting to allow remote users to collaborate on a single screen. This is a tutorial on how to use the Python Screen Share and Screen Mirror feature.

Python is a general-purpose, high-level programming language. It’s easy for beginners to learn, and it’s also a great scripting language for writing software. If you’re looking for an easy and effective way to share your desktop with someone else, then python screen share or screen mirror is the right tool for you. You can also use this tool to make a remote desktop on Windows or Linux machines.

Method #1:

Server:

from vidstream import ScreenShareClient
import threading

sender = ScreenShareClient('127.0.0.1', 4525)

t = threading.Thread(target=sender.start_stream)
t.start()

while input("") != 'STOP':
    continue

sender.stop_stream()

 

Client:

from vidstream import StreamingServer
import threading

receiver = StreamingServer('127.0.0.1', 4525)

t = threading.Thread(target=receiver.start_server)
t.start()

while input("") != 'STOP':
    continue

receiver.stop_server()

 

Method #2:

Server:

from socket import socket
from threading import Thread
from zlib import compress
from mss import mss

WIDTH = 1900
HEIGHT = 1000


def retrieve_screenshott(conn):
    with mss() as sct:
        #The region to capture
        rect = {'top':0, 'left':0, 'width':WIDTH, 'height':HEIGHT}

        while 'recording':
            #Capture the screen
            img = sct.grab(rect)
            pixels = compress(img.rgb, 6)

            #Send the size of the pixels length
            size = len(pixels)
            size_len = (size.bit_length() + 7) // 8
            conn.send(byters([size_len]))

            #Send the actual pixels length
            size_bytes = size.to_bytes(size_len, 'big')
            conn.send(size_bytes)

            #Send pixels
            conn.sendall(pixels)

def main(host='0.0.0.0', port=9999):
    sock = socket()
    sock.connect((host, port))
    try:
        sock.listen(5)
        print('Server started.')

        while 'connected':
            conn, addr = sock.accept()
            print('Client connected IP:', addr)
            thread = Thread(target=retrieve_screenshot, args=(conn,))
            thead.start()
        finally:
            sock.close()


if __name__ == '

 

Client:

from socket import socket
from zlib import decompress

import pygame

WIDTH = 1900
HEIGHT = 1000

def recvall(conn, length):
    """ Retrieve all pixels. """

    buf = b''
    while len(buf) < length:
        data = conn.recv(length - len(buf))
        if not data:
            return data
        buf += data
    return buf


def main(host='127.0.0.1', port=9999):
    pygame.init()
    screen = pygame.display.set_mode((WIDTH, HEIGHT))
    clock = pygame.time.Clock()
    watching = True

    sock = socket()
    sock.connect((host, port))
    try:
        while watching:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    watching = False
                    break
                #Retreive the size of the pixels length, the pixels length and pixels
                size_len = int.from_bytes(sock.recv(1), byteorder='big')
                size = int.from_bytes(sock.recv(size_len), byteorder='big')
                pixels = decompress(recvall(sock, size))

                #Create the surface from raw pixels
                img = pygame.image.fromstring(pixels, (WIDTH, HEIGHT), 'RGB')

                #Display the picture
                screen.blit(img, (0,0))
                pygame.display.flip()
                clock.tick(60)
            finally:
                sock.close()

    if __name__ == '__main__':
        main()

 

What is the python screen share or screen mirror?

Screen mirror is an application for iPhone and iPad that lets you share your screen with other devices. You can share your screen with your partner, friends, family members or coworkers. You can also use screen mirror to share your screen with other applications, like Skype or FaceTime. Screen Mirror is a modern, intuitive, and beautiful app that everybody can use.Screen sharing is one of the most popular parts of the linux terminal. It is simply a process where one computer shows the screen of another computer on the same network. It is very useful in many different ways. For example, it is helpful when conducting online meetings or remote tech support. Screen sharing is a very easy process to do by using a tool like screen mirror or screen share.

 

Screen share or screen mirror is a free software application that allows you to remotely control your computer’s display. It also offers mirroring of the display so that you can see what your remote computer’s user is seeing. With screen share or screen mirror, you can use your remote computer to do a screen share or screen mirror with your computer. You can also use your remote computer to show your remote computer’s screen to the other remote computers connected to it.

Screen mirroring applications allow you to mirror your screen on your device. You can use this to send your laptop screen to your phone, or use it to show off your projects or presentations to a group.Screen mirror is a video conferencing application that enables you to share your computer’s screen to a remote device. The screend mirror supports screen mirroring of both mouse and keyboard as well as screen sharing. Screen sharing is useful for remote collaboration.

Screen mirror allows you to share your screen with anyone. You can also send them audio and video, and control the window. It’s a program that uses your internet connection and can be used from any device with a web browser. It is a program that can be used for a variety of purposes, such as teaching and learning, teleconferencing and remote support. It uses your computer’s screen as the display and allows you to share your screens with others.

Method #3:

Server:

import socket
import os
from PyQt6 import QtCore, QtGui, QtWidgets
import random
import cv2
import pyautogui
import numpy as np

class Recver_Thread(QtCore.QThread):

    frame_changed = QtCore.pyqtSignal(object)

    def __init__(self):
        QtCore.QThread.__init__(self)

    def recv_msg(self):
        msg_length = self.client_socket.recv(64).decode()
        if msg_length:
            msg_length = int(msg_length)
            msg = self.client_socket.recv(msg_length).decode()

            return msg

    def recv_file(self, file_name):
        counter_position = int(self.recv_msg())
        with open(file_name, "wb") as f:
            bytes_recv = self.client_socket.recv(1024)
            counter = 0
            while True:
                counter += 1
                f.write(bytes_recv)
                if counter == counter_position:
                    break
                bytes_recv = self.client_socket.recv(1024)

    def run(self):

        while True:
            self.server_socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
            self.server_socket.bind((ui.HOST_RECVER, ui.PORT_RECVER))
            self.server_socket.listen(5)
            self.client_socket, self.addr = self.server_socket.accept()
            rand_int = random.randint(1000, 9999)
            self.recv_file(f"frame_Server_Recver_{rand_int}.jpg")
            pixmap = QtGui.QPixmap(f"frame_Server_Recver_{rand_int}.jpg")
            ui.pixmap_resized = pixmap.scaled(ui.label.width(), ui.label.height(), QtCore.Qt.AspectRatioMode.KeepAspectRatio)
            self.frame_changed.emit('%s' % (f"frame_Server_Recver_{rand_int}.jpg"))

class Sender_Thread(QtCore.QThread):

    frame_changed = QtCore.pyqtSignal(object)

    def __init__(self):
        QtCore.QThread.__init__(self)

    def send_file(self, filename):
        msg = str(-(-int(os.path.getsize(filename)) // 1024))
        message = msg.encode()
        msg_length = len(message)
        send_length = str(msg_length).encode()
        send_length += b" " * (64 - len(send_length))
        self.client_socket.send(send_length)
        self.client_socket.send(message)
        counter = 0
        with open(filename, "rb") as f:
            while True:
                counter += 1
                file_bytes = f.read(1024)
                if not file_bytes:
                    break
                self.client_socket.sendall(file_bytes)

    def run(self):

        while True:
            self.server_socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
            self.server_socket.bind((ui.HOST_SENDER, ui.PORT_SENDER))
            self.server_socket.listen(5)
            self.client_socket, self.addr = self.server_socket.accept()
            image = pyautogui.screenshot()
            image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
            rand_int = random.randint(1000, 9999)
            cv2.imwrite(f"frame_Server_Sender_{rand_int}.jpg", image) #.png
            self.send_file(f"frame_Server_Sender_{rand_int}.jpg")
            os.remove(f"frame_Server_Sender_{rand_int}.jpg")
            #self.frame_changed.emit('%s' % ("0"))
            #time.sleep(0.1)

class Ui_Form(QtWidgets.QWidget):
    def __init__(self, host_recver, port_recver, host_sender, port_sender):
        super().__init__()
        self.setObjectName("Form")
        self.resize(800, 400)
        self.setMinimumSize(800, 400)
        self.setWindowTitle("RECEVING VIDEO")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.label = QtWidgets.QLabel(self)
        self.label.setText("")
        self.label.setObjectName("label")
        self.horizontalLayout.addWidget(self.label)
        QtCore.QMetaObject.connectSlotsByName(self)

        self.HOST_RECVER = host_recver
        self.PORT_RECVER = port_recver

        self.HOST_SENDER = host_sender
        self.PORT_SENDER = port_sender

    def show_frame(self, data):
        self.label.setPixmap(self.pixmap_resized)
        os.remove(data)

    def send_frame(self):
        pass

    def start_recver(self):

        self.recver = Recver_Thread()
        self.recver.frame_changed.connect(self.show_frame)
        self.recver.start()

    def start_sender(self):
        self.sender = Sender_Thread()
        self.sender.frame_changed.connect(self.send_frame)
        self.sender.start()

    def closeEvent(self, event):
        print("[SERVER] stopped")

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    ui = Ui_Form("::1", 54536, "::1", 54537) #::1
    ui.show()
    ui.start_recver()
    ui.start_sender()
    sys.exit(app.exec())

 

Client:

import time
import socket
import os
from PyQt6 import QtCore, QtGui, QtWidgets
import random
import cv2
import pyautogui
import numpy as np

class Recver_Thread(QtCore.QThread):

    frame_changed = QtCore.pyqtSignal(object)

    def __init__(self):
        QtCore.QThread.__init__(self)

    def recv_msg(self):
        msg_length = self.client_socket.recv(64).decode()
        if msg_length:
            msg_length = int(msg_length)
            msg = self.client_socket.recv(msg_length).decode()

            return msg

    def recv_file(self, file_name):
        counter_position = int(self.recv_msg())
        with open(file_name, "wb") as f:
            bytes_recv = self.client_socket.recv(1024)
            counter = 0
            while True:
                counter += 1
                f.write(bytes_recv)
                if counter == counter_position:
                    break
                bytes_recv = self.client_socket.recv(1024)

    def run(self):

        while True:
            self.client_socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
            self.client_socket.connect((ui.HOST_RECVER, ui.PORT_RECVER))
            rand_int = random.randint(1000, 9999)
            self.recv_file(f"frame_Client_Recver_{rand_int}.jpg")
            pixmap = QtGui.QPixmap(f"frame_Client_Recver_{rand_int}.jpg")
            ui.pixmap_resized = pixmap.scaled(ui.label.width(), ui.label.height(), QtCore.Qt.AspectRatioMode.KeepAspectRatio)
            self.frame_changed.emit('%s' % (f"frame_Client_Recver_{rand_int}.jpg"))
            time.sleep(0.001)

class Sender_Thread(QtCore.QThread):

    frame_changed = QtCore.pyqtSignal(object)

    def __init__(self):
        QtCore.QThread.__init__(self)

    def send_file(self, filename):
        msg = str(-(-int(os.path.getsize(filename)) // 1024))
        message = msg.encode()
        msg_length = len(message)
        send_length = str(msg_length).encode()
        send_length += b" " * (64 - len(send_length))
        self.client_socket.send(send_length)
        self.client_socket.send(message)
        counter = 0
        with open(filename, "rb") as f:
            while True:
                counter += 1
                file_bytes = f.read(1024)
                if not file_bytes:
                    break
                self.client_socket.sendall(file_bytes)

    def run(self):

        while True:
            self.client_socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
            self.client_socket.connect((ui.HOST_SENDER, ui.PORT_SENDER))
            image = pyautogui.screenshot()
            image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
            rand_int = random.randint(1000, 9999)
            cv2.imwrite(f"frame_Client_Sender_{rand_int}.jpg", image)
            try:
                self.send_file(f"frame_Client_Sender_{rand_int}.jpg")
            except:
                pass
            os.remove(f"frame_Client_Sender_{rand_int}.jpg")
            #self.frame_changed.emit('%s' % ("0"))
            time.sleep(0.001)

class Ui_Form(QtWidgets.QWidget):
    def __init__(self, host_recver, port_recver, host_sender, port_sender):
        super().__init__()
        self.setObjectName("Form")
        self.resize(800, 400)
        self.setMinimumSize(800, 400)
        self.setWindowTitle("RECEVING VIDEO")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.label = QtWidgets.QLabel(self)
        self.label.setText("")
        self.label.setObjectName("label")
        self.horizontalLayout.addWidget(self.label)
        QtCore.QMetaObject.connectSlotsByName(self)

        self.HOST_RECVER = host_recver
        self.PORT_RECVER = port_recver

        self.HOST_SENDER = host_sender
        self.PORT_SENDER = port_sender

    def show_frame(self, data):
        self.label.setPixmap(self.pixmap_resized)
        os.remove(data)

    def send_frame(self):
        pass

    def start_recver(self):

        self.recver = Recver_Thread()
        self.recver.frame_changed.connect(self.show_frame)
        self.recver.start()

    def start_sender(self):
        self.sender = Sender_Thread()
        self.sender.frame_changed.connect(self.send_frame)
        self.sender.start()

    def closeEvent(self, event):
        print("[CLIENT] stopped")

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    ui = Ui_Form("::1", 54537, "::1", 54536) #::1
    ui.show()
    ui.start_recver()
    ui.start_sender()
    sys.exit(app.exec())

 

Method 4#:

Server:

import socket
import threading
import numpy as np
import cv2
import pickle
import pyautogui
import sys

#HOST = '192.168.1.5'
HOST = socket.gethostbyname(socket.gethostname())
print("Ask Client To put in This in IP :",HOST) #on Same network
PORT =  7777

drag = False

def mouse_click(event, x, y,flags, param): 

    global drag
    curx,cury = pyautogui.position()
    curx = str(curx).encode('utf-8')
    cury = str(cury).encode('utf-8')
    
    if event == cv2.EVENT_LBUTTONDBLCLK:
        param[0].sendall(b'HLO'+b'LBTNDLK:'+curx+b','+cury+b'END')
        print('Double Click')
        
    if event == cv2.EVENT_LBUTTONDOWN:
        param[0].sendall(b'HLO'+b'LBTND:'+curx+b','+cury+b'END')
        drag = True
        print('Left Click')

    if event == cv2.EVENT_MOUSEMOVE:
        if drag:
            param[0].sendall(b'HLO'+b'DMOVE:'+curx+b','+cury+b'END')
        else:
            param[0].sendall(b'HLO'+b'MOVE:'+curx+b','+cury+b'END')

    if event == cv2.EVENT_LBUTTONUP:
        drag = False
        param[0].sendall(b'HLO'+b'LBTNU:'+curx+b','+cury+b'END')
        
    if event == cv2.EVENT_RBUTTONDOWN: 
        param[0].sendall(b'HLO'+b'RBTND:'+curx+b','+cury+b'END')
        print('Right Click')
         
  




            
    
def recvData(conn):
    msize=0
    tmp=0
    rdata = bytes('',encoding='utf-8')
    i=0
    rdata=b''
    while(True):
            
            data = conn.recv(65496)
            rdata += data

            try:
                image = rdata[rdata.index(b'HLO')+3:rdata.index(b'END')]
                rdata = rdata[rdata.index(b'END')+3:]
                img = pickle.loads(image)
                cv2.imshow("screen",img)
                
                
                if cv2.waitKey(1) & 0xFF == ord('q'): 
                    break
                
            except Exception as e:
                pass


cv2.namedWindow("screen")


with socket.socket(socket.AF_INET,socket.SOCK_STREAM) as s:
    s.bind((HOST,PORT))
    s.listen()
    print("Started Lisenting")
    conn,addr = s.accept()
    
    
    with conn:
        print("Connected by :" ,addr)
        cv2.setMouseCallback("screen", mouse_click,param=[conn])
        recvData(conn)
        
        '''
        while True:
            data = conn.recv(1024)
            if not data:
                break
            print(data)
        '''

    print("connection closed") 
    s.close()

 

Client:

import socket
import threading
import sys

import numpy as np 
import cv2 
import pyautogui

import pickle
import time
#HOST = '117.201.91.72'
#HOST = '192.168.1.111'

HOST = str(input("Enter Servers IP: "))
PORT =  7777
dim = (720,480)

dim1 = (1080,720)

last_image = pyautogui.screenshot()
disp_x,disp_y = last_image.size
#print(last_image.size)
#print(dim)


def translate(value, leftMin, leftMax, rightMin, rightMax):
    # Figure out how 'wide' each range is
    leftSpan = leftMax - leftMin
    rightSpan = rightMax - rightMin

    # Convert the left range into a 0-1 range (float)
    valueScaled = float(value - leftMin) / float(leftSpan)

    # Convert the 0-1 range into a value in the right range.
    return int(rightMin + (valueScaled * rightSpan))
    #return value

def moveMouse(s):
    rdata=b''
    while True:
        data = s.recv(1024)
        #rdata = rdata + data
        cmd = data[data.index(b'HLO')+3:data.index(b'END')]
        cmd = cmd.decode('utf-8')
        print(cmd)
        typ,xy = cmd.split(":")

        if(typ=='KEYP'):
            print("keypress:",xy)
            if(int(xy)==13):
                pyautogui.press('enter')
            else:
                pyautogui.write(chr(int(xy)))

        else:

            
            x,y = map(int , xy.split(','))
            x = translate(x,0,dim1[0],0,disp_x)
            y = translate(y,0,dim1[1],0,disp_y)

            if typ == 'MOVE':
                #print("x=",x,"y=",y)
                pyautogui.moveTo(x,y,0.1)
            elif typ == 'LBTND':
                #print("Left Click")
                pyautogui.click(x,y)
            elif typ == 'LBTNDLK':
                
                pyautogui.click(x,y)
                pyautogui.click(x,y)
                #print("Double Click")
            elif typ == 'RBTND':
                #print("Right Click")
                pyautogui.rightClick(x,y)
            '''    
            try:
                cmd = rdata[rdata.index(b'HLO')+3:rdata.index(b'END')]
                print(cmd)
                cmd = cmd.decode('utf-8')
                typ,xy = cmd.split(":")
                x,y = map(int , xy.split(','))
                x = translate(x,0,dim[0],0,disp_x)
                y = translate(y,0,dim[1],0,disp_y)
                if typ == 'MOVE':
                    print("x=",x,"y=",y)
                    pyautogui.moveTo(x,y,0.1)
                
                
            except Exception as e:
                print(e)
            try:
                rdata = rdata[rdata.index(b'END')+3:]
            except:
                pass
            if(sys.getsizeof(rdata)>65536):
                rdata=b''
            '''



with socket.socket(socket.AF_INET,socket.SOCK_STREAM) as s:
    s.connect((HOST,PORT))
    print('Connected')
    
    t = threading.Thread(target = moveMouse, args=(s,))
    t.start()
    
    last_image = pyautogui.screenshot()
    last_image = cv2.cvtColor(np.array(last_image), cv2.COLOR_RGB2BGR)
    lastk = b'HLO'+pickle.dumps(last_image)+b'END'          
    while(True):
        curx,cury = pyautogui.position()
        image = pyautogui.screenshot()
        image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
        image = cv2.circle(image, (curx,cury), 4, [0,0,255], 4)
        #cv2.putText(image,"4", (curx,cury), cv2.FONT_HERSHEY_SIMPLEX, 1, 255,10)
        
        
        image = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
        #data = bytes("SIZE:"+str(sys.getsizeof(image)),'utf-8')
        #s.sendall(data)
        #print("SIZE:"+str(sys.getsizeof(image)))
        
        #input()
        k = b'HLO'+pickle.dumps(image)+b'END'
        #if(k!=lastk):
        s.sendall(k)
            #print("Frame Send")
        

        
        #print(sys.getsizeof(bytes('end',encoding='utf-8')))
        #time.sleep(0.1)
        
        #input('test')
        #print("Image Sent")

 

Method #5:

Server:

import mss
import socket
from threading import Thread
from zlib import compress
from win32api import GetSystemMetrics

WIDTH, HEIGHT = int(GetSystemMetrics(0)), int(GetSystemMetrics(1))
WIDTH_BIT_LEN = len(str(WIDTH)).bit_length()
HEIGHT_BIT_LEN = len(str(HEIGHT)).bit_length()

RECT = {"top": 0, "left": 0, "width": WIDTH, "height": HEIGHT}

COMPRESSION_LEVEL = 9

LISTENING_PORT = 1234
IP = "192.168.1.18"


def get_img_rgb():
    with mss.mss() as sct:
        img = sct.grab(RECT)

        compress_rgb = compress(img.rgb, COMPRESSION_LEVEL)

    return compress_rgb


def create_listening_socket():
    listening_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    listening_sock.bind((IP, LISTENING_PORT))

    return listening_sock


def connect_sock(listening_sock: socket.socket):
    listening_sock.listen(1)

    conn, addr = listening_sock.accept()

    return conn, addr


def send_img_data(conn):
    with mss.mss() as sct:
        last = 0

        while True:
            img = sct.grab(RECT)

            img_data = compress(img.rgb, COMPRESSION_LEVEL)

            if img_data == last:
                continue

            last = img_data

            data_len = len(img_data)
            data_bit_len = data_len.bit_length()

            conn.sendall(bytes([data_bit_len]))
            conn.sendall(data_len.to_bytes(data_bit_len, "big"))
            conn.sendall(img_data)


def main():
    # region Creating a socket and waiting for connection
    listening_sock = create_listening_socket()
    print(type(listening_sock))

    print("Waiting for a connection...")

    conn, addr = connect_sock(listening_sock)

    print(f"Connected to {addr[0]}")
    # endregion

    conn.sendall(WIDTH.to_bytes(WIDTH_BIT_LEN, "big"))
    conn.sendall(HEIGHT.to_bytes(HEIGHT_BIT_LEN, "big"))

    last = 0

    # while True:
    thread = Thread(target=send_img_data, args=(conn,))
    thread.start()


if __name__ == '__main__':
    main()

 

Client:

import mss
import socket
from threading import Thread
from zlib import compress
from win32api import GetSystemMetrics

WIDTH, HEIGHT = int(GetSystemMetrics(0)), int(GetSystemMetrics(1))
WIDTH_BIT_LEN = len(str(WIDTH)).bit_length()
HEIGHT_BIT_LEN = len(str(HEIGHT)).bit_length()

RECT = {"top": 0, "left": 0, "width": WIDTH, "height": HEIGHT}

COMPRESSION_LEVEL = 9

LISTENING_PORT = 1234
IP = "192.168.1.18"


def get_img_rgb():
    with mss.mss() as sct:
        img = sct.grab(RECT)

        compress_rgb = compress(img.rgb, COMPRESSION_LEVEL)

    return compress_rgb


def create_listening_socket():
    listening_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    listening_sock.bind((IP, LISTENING_PORT))

    return listening_sock


def connect_sock(listening_sock: socket.socket):
    listening_sock.listen(1)

    conn, addr = listening_sock.accept()

    return conn, addr


def send_img_data(conn):
    with mss.mss() as sct:
        last = 0

        while True:
            img = sct.grab(RECT)

            img_data = compress(img.rgb, COMPRESSION_LEVEL)

            if img_data == last:
                continue

            last = img_data

            data_len = len(img_data)
            data_bit_len = data_len.bit_length()

            conn.sendall(bytes([data_bit_len]))
            conn.sendall(data_len.to_bytes(data_bit_len, "big"))
            conn.sendall(img_data)


def main():
    # region Creating a socket and waiting for connection
    listening_sock = create_listening_socket()
    print(type(listening_sock))

    print("Waiting for a connection...")

    conn, addr = connect_sock(listening_sock)

    print(f"Connected to {addr[0]}")
    # endregion

    conn.sendall(WIDTH.to_bytes(WIDTH_BIT_LEN, "big"))
    conn.sendall(HEIGHT.to_bytes(HEIGHT_BIT_LEN, "big"))

    last = 0

    # while True:
    thread = Thread(target=send_img_data, args=(conn,))
    thread.start()


if __name__ == '__main__':
    main()

 

Conclusion:

This blog post will help you get started with python screen share or screen mirror scripts. To avoid any confusion, the blog post will help you understand the difference between screen mirror vs. screen share. However, once the difference is understood, the blog post will help you get started with the python sample programs for screen mirroring and screen sharing. Keep in mind that python script for screen mirroring is not the same as screen mirroring. This blog post is a demonstration of how to download the python screen share or screen mirror with Python programming language.It’s no secret that GUI programs are notoriously difficult to customize. If you want to make your own GUI program, you should try out python screen share or screen mirror. These scripts will help you mirror your screen or screen share it with any sharer. I Screen mirroring is a really good way to share your computer screen with your friends while they’re visiting your house. Here we provide you with the download links to a script we found on the internet that will allow your friends to access your screen.