Send screen via socket problem for systemd (I think)

Cigaras

New Member
server.py
Python:
import socket
import cv2
import struct
import numpy as np
from PIL import ImageGrab
from time import sleep
import pickle

con = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
con.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
con.bind(("localhost",3344))
con.listen(1)
while True:
   
    conn , addr = con.accept()
    if conn:
        break
    else:
        continue
data = b''
payload_size = struct.calcsize("L")

while True:
    sleep(0.2)
    while len(data) < payload_size:
        data += conn.recv(4096)
    packed_msg_size = data[:payload_size]
    data = data[payload_size:]
    msg_size = struct.unpack("L", packed_msg_size)[0] ### CHANGED
    while len(data) < msg_size:
        data += conn.recv(4096)

    frame_data = data[:msg_size]
    data = data[msg_size:]

   
    frame = pickle.loads(frame_data)
    cv2.imshow("rrame",frame)
                 
    if (cv2.waitKey(1) & 0XFF) == ord('q'):
        break

cv2.destroyAllWindows()
conn.close()
con.close()

client.py

Python:
import socket
import cv2
import pyscreenshot  as ImageGrab
import numpy as np
import pickle
import struct


sock_u = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
while True:
    try:
        sock_u.connect(("localhost",3344))
        break
    except:
        continue
while True:
       
   
    img = ImageGrab.grab(bbox=(0,0,500,500))
    frame = np.asanyarray(img)
    data = pickle.dumps(frame)
    message_size = struct.pack("L", len(data))
    sock_u.sendall(message_size + data)


cv2.destroyAllWindows()
con.close()

client.service


Code:
[Unit]
Description =  Send screenshot via socket/tcp

After=network.target

PartOf=graphical-session.target

[Service]


RemainAfterExit=no
Type=simple
Requires=network.target graphical.target
Environment="DISPLAY=:0.0"
Environment="XAUTHORY=$XAUTHORY"
ExecStart=/usr/bin/python3 /root/cli.py

[Install]
WantedBy=graphical.target

Hello

#./ systemctl enable /lib/systemd/system/cli.service
#./ systemctl daemon-reload
#./ systemctl start cli.service


I install like that but I have a problem. They are running when system opened as root user. But when I login machine as a normal user it is not working. Can you help me about problem . How can I fix that ?

Note:Change ip's etc. for your computer
 

Members online


Latest posts

Top