/// <summary> /// Each client connection will be served by this thread. /// </summary> /// <param name="client"></param> private void ClientThread(object client) { Socket socket = (Socket)client; System.Diagnostics.Debug.WriteLine(string.Format("New client from {0}", socket.RemoteEndPoint.ToString())); lock (_Clients) _Clients.Add(socket); try { using (MjpegWriter wr = new MjpegWriter(new NetworkStream(socket, true))) { // Writes the response header to the client. wr.WriteHeader(); if (decoder != null) { while (true) { if (this.Interval > 0) { Thread.Sleep(this.Interval); } if (JpegBytes != null) { wr.Write(JpegBytes); } } } else { // Streams the images from the source to the client. foreach (var imgStream in Screen.Streams(this.ImagesSource)) { wr.Write(imgStream); } } } } catch { } finally { lock (_Clients) _Clients.Remove(socket); } }
/// <summary> /// Each client connection will be served by this thread. /// </summary> /// <param name="client"></param> private void ClientThread(object client) { Socket socket = (Socket)client; System.Diagnostics.Debug.WriteLine(string.Format("New client from {0}",socket.RemoteEndPoint.ToString())); lock (_Clients) _Clients.Add(socket); try { using (MjpegWriter wr = new MjpegWriter(new NetworkStream(socket, true))) { // Writes the response header to the client. wr.WriteHeader(); if (decoder != null) { while (true) { if (this.Interval > 0) Thread.Sleep(this.Interval); if (JpegBytes != null) wr.Write(JpegBytes); } } else { // Streams the images from the source to the client. foreach (var imgStream in Screen.Streams(this.ImagesSource)) { wr.Write(imgStream); } } } } catch { } finally { lock (_Clients) _Clients.Remove(socket); } }