Advertisement
lol4325

Untitled

Sep 8th, 2023
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import cv2
  2. import socket
  3. import numpy as np
  4. import threading
  5.  
  6. # Client configuration
  7. host = '192.168.56.1' # Replace with the server's IP address
  8. port = 8080
  9.  
  10. # Create a socket
  11. client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  12. client_socket.connect((host, port))
  13.  
  14. def receive_screen():
  15. while True:
  16. try:
  17. # Receive the frame size
  18. frame_size = int.from_bytes(client_socket.recv(4), byteorder='big')
  19.  
  20. # Receive the frame data
  21. frame_data = b''
  22. while len(frame_data) < frame_size:
  23. frame_data += client_socket.recv(frame_size - len(frame_data))
  24.  
  25. # Convert the frame data to an image
  26. frame = cv2.imdecode(np.frombuffer(frame_data, dtype=np.uint8), 1)
  27.  
  28. # Display the frame
  29. cv2.imshow('Remote Screen', frame)
  30.  
  31. # Close the window when 'q' is pressed
  32. if cv2.waitKey(1) & 0xFF == ord('q'):
  33. break
  34.  
  35. except KeyboardInterrupt:
  36. break
  37.  
  38. # Clean up
  39. cv2.destroyAllWindows()
  40. client_socket.close()
  41.  
  42. # Start receiving and displaying the screen in a separate thread
  43. receive_thread = threading.Thread(target=receive_screen)
  44. receive_thread.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement