1

Code:

'''pygame.init()
    screen = pygame.display.set_mode((950, 500))
    clock = pygame.time.Clock()
    max_bytes = 64000
    udp_conn = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    udp_conn.bind(('0.0.0.0', 5000))
    run = True
    while run:
        size_msg, address = udp_conn.recvfrom(max_bytes)
        size = int.from_bytes(size_msg, byteorder='big')
        while size > 10000000:  # if size is greater than 10M then loop has to fire to get value of the size of
            # the compressed img.
            size = int.from_bytes(size_msg, byteorder='big')
        pixels = recvall(size, udp_conn, max_bytes)
        try:
            pixels = decompress(pixels)
            scrn_img = pygame.image.fromstring(str(pixels), (950, 500), 'RGB')
            scrn_shot = pygame.transform.scale(scrn_img, (950, 500))
            screen.blit(scrn_shot, (0, 0))
            pygame.display.flip()
            clock.tick(60)
        except:
            pass
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    run = False
                    sys.exit()'''

I'm trying to get screenshots from other computer and then load them on the screen, but screen just does not respond from the start and then crashes. Does someone know why does it crash?

  • The ```size_msg, address = udp_conn.recvfrom(max_bytes)``` and all ```recv``` functions usually are blocking functions and are most probably what you need to take care of. Have you tried taking a look at that? – Shufi123 May 28 '21 at 15:06

0 Answers0