Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import socket
- import numpy as np
- import threading
- # Client configuration
- host = '192.168.56.1' # Replace with the server's IP address
- port = 8080
- # Create a socket
- client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- client_socket.connect((host, port))
- def receive_screen():
- while True:
- try:
- # Receive the frame size
- frame_size = int.from_bytes(client_socket.recv(4), byteorder='big')
- # Receive the frame data
- frame_data = b''
- while len(frame_data) < frame_size:
- frame_data += client_socket.recv(frame_size - len(frame_data))
- # Convert the frame data to an image
- frame = cv2.imdecode(np.frombuffer(frame_data, dtype=np.uint8), 1)
- # Display the frame
- cv2.imshow('Remote Screen', frame)
- # Close the window when 'q' is pressed
- if cv2.waitKey(1) & 0xFF == ord('q'):
- break
- except KeyboardInterrupt:
- break
- # Clean up
- cv2.destroyAllWindows()
- client_socket.close()
- # Start receiving and displaying the screen in a separate thread
- receive_thread = threading.Thread(target=receive_screen)
- receive_thread.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement