示例#1
0
        /// <summary>
        /// Opens a connection to the encoder on the indicated channel.
        /// </summary>
        public bool Open()
        {
            log.Context = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                m_sLastError = "";
                if (m_conn != null)
                {
                    log.WriteLog("Connection still opened. Closing...");
                    m_conn.Stop();
                    m_conn = null;
                }
                m_TCPClient.Connect(m_sServerAddress,m_iPort);
                m_conn = new Connection(ref m_TCPClient,m_EventChannelConnectionComplete,ref log);
                m_conn.MessageReceived += new Connection.MessageReceivedHandler(m_conn_MessageReceived);
                m_conn.OnConnectionError +=new Connection.OnConnectionErrorHandler(m_conn_OnConnectionError);
                m_conn.Start();
            }
            catch (System.Net.Sockets.SocketException sex)
            {
                log.WriteLog(sex.Message);
                if (m_conn != null)
                {
                    m_conn = null;
                }
                m_sLastError = sex.Message;
                return false;
            }
            return true;
        }
示例#2
0
        /// <summary>
        /// starts a recording using the MediaTitle parameter. The file will be retrieved using the MediaTitle or MediaTitle.wmv. Check LastError if false returned.
        /// </summary>
        public bool Close()
        {
            log.Context = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name;
            if (m_conn != null)
            {
                if(m_conn.Connected)
                {

                    m_conn.Stop();
                    if (!m_EventChannelConnectionComplete.WaitOne(30000,false))
                    {
                        log.WriteLog("Timeout waiting for connection thread to complete.");
                        throw new System.ApplicationException("Timeout waiting for connection thread to complete.");
                    }

                    m_conn = null;
                }
                if(m_TCPClient != null)
                {
                    log.WriteLog("...Releasing tcpclient socket");
                    try
                    {

                        //m_TCPClient.GetStream().Close();
                        m_TCPClient.Close();
                        m_TCPClient = null;
                    }
                    catch(Exception Err)
                    {
                        log.WriteLog("... socket error occurred: " + Err.Message);
                        string peekError = Err.Message;
                    }
                    log.WriteLog("... socket released with success");
                }
                return true;
            }
            // you're not even connected, man!
            return false;
        }