public static void Start() { if (Available) { return; } if (_server == null) { _server = new RenderServer(ServerPort, BroadcastPort, false); _server.OnServerException += (a, b) => OnServerException?.Invoke(a, b); _server.OnBroadcastException += (a, b) => OnBroadcastException?.Invoke(a, b); _server.OnServerDiscovered += (a, b, c) => OnDiscoveredServer?.Invoke(a, b, c); } _server.Start(); }
/// <summary> /// Starts the Listener background thread for rendering /// </summary> private void StartRenderListener() { _listenerThread = new Thread(async() => { try { Listener = new TcpListener(IPAddress.Any, Port); Listener.Start(); while (Active) { TcpClient client = await Listener.AcceptTcpClientAsync(); RenderServerClientTcp rClient = new RenderServerClientTcp(Blender, client); lock (Clients) Clients.Add(rClient); rClient.OnDisconnect += (client) => { lock (Clients) Clients.Remove(client); }; Thread.Sleep(100); } } catch (Exception ex) { Console.WriteLine("TCP Exception:" + ex.Message); OnServerException?.Invoke(this, ex); } finally { Active = false; } }); _listenerThread.Start(); }