Provides a stream writer that can be used to write images as MJPEG or (Motion JPEG) to any stream.
Inheritance: IDisposable
コード例 #1
0
ファイル: VideoFeed.cs プロジェクト: sm6uax/plegma
        //------------------------------------------------------------------------------------------------------------------------
        public void AddClient(Socket ClientSocket)
        {
            //prepare MjpegWriter and write header for client
            MjpegWriter wr;

            try
            {
                //create writer
                wr = new MjpegWriter(new NetworkStream(ClientSocket, true));
                // Writes the response header to the client.
                wr.WriteHeader();

                //client is now ready for streaming
                var clientInfo = new ClientInfo()
                {
                    Socket = ClientSocket,
                    Writer = wr,
                };
                lock (_Clients)
                    if (!IsDisposed)
                    {
                        _Clients.Add(ClientSocket, clientInfo);
                    }
                    else
                    {
                        //we are disposed, so close client socket
                        try
                        {
                            ClientSocket.Close();
                            ClientSocket.Dispose();
                        }
                        catch { }
                    }
            }
            catch (Exception ex)
            {
                DebugEx.TraceLog("Streaming Error: " + ex.Message);
                //close socket on error
                try
                {
                    ClientSocket.Close();
                    ClientSocket.Dispose();
                }
                catch { }
            }
        }
コード例 #2
0
ファイル: VideoFeed.cs プロジェクト: yodiwo/plegma
        //------------------------------------------------------------------------------------------------------------------------
        public void AddClient(Socket ClientSocket)
        {
            //prepare MjpegWriter and write header for client
            MjpegWriter wr;
            try
            {
                //create writer
                wr = new MjpegWriter(new NetworkStream(ClientSocket, true));
                // Writes the response header to the client.
                wr.WriteHeader();

                //client is now ready for streaming
                var clientInfo = new ClientInfo()
                {
                    Socket = ClientSocket,
                    Writer = wr,
                };
                lock (_Clients)
                    if (!IsDisposed)
                        _Clients.Add(ClientSocket, clientInfo);
                    else
                    {
                        //we are disposed, so close client socket
                        try
                        {
                            ClientSocket.Close();
                            ClientSocket.Dispose();
                        }
                        catch { }
                    }
            }
            catch (Exception ex)
            {
                DebugEx.TraceLog("Streaming Error: " + ex.Message);
                //close socket on error
                try
                {
                    ClientSocket.Close();
                    ClientSocket.Dispose();
                }
                catch { }
            }
        }