Exemplo n.º 1
0
        // Start serving up frames
        private void DoItVoices(WinSound.Recorder m_Recorder, TcpServer serv, StreamWriter sw)
        {
            do
            {
                // Wait til a client connects before we start the graph
                ConnectionReadyVoices.WaitOne();

                if (waveindevices.Count > 0)
                {
                    // While not shutting down, and still at least one client
                    while ((!bShutDown) && (serv.Connections > 0))
                    {
                        try
                        {
                            m_Recorder.Start(waveindevices[0], SAMPLE_PER_SECONDS, BIT_PER_SAMPLE, CHANNEL, BUFFER_COUNT, BUFFER_SIZE);
                        }
                        catch (Exception ex)
                        {
                            try
                            {
                                sw.WriteLine(DateTime.Now.ToString());
                                sw.WriteLine(ex);
                            }
                            catch { }
                        }
                    }
                }

                // Clients have all disconnected.  Pause, then sleep and wait for more
                m_Recorder.Stop();
                sw.WriteLine("record dropped");
            } while (!bShutDown);
        }
Exemplo n.º 2
0
        public void RunVoiceServer()
        {
            const int TCPLISTENPORTVoices = 499;



            m_Recorder = new WinSound.Recorder();



            // Set up logging
            string       path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Voices.log";
            StreamWriter sw   = File.AppendText(path);

            try
            {
                // Set up member vars
                ConnectionReadyVoices = new ManualResetEvent(false);
                bShutDownVoices       = false;

                InitRecorder();

                // Set up tcp server
                System.Net.IPAddress[] testVoices = TcpServer.GetAddresses();
                System.Net.IPAddress   ipv4Voices = null;
                // IPAddress class contains the address of a computer on an IP network.
                foreach (System.Net.IPAddress _IPAddressVoices in testVoices)
                {
                    // InterNetwork indicates that an IP version 4 address is expected
                    // when a Socket connects to an endpoint
                    if (_IPAddressVoices.AddressFamily.ToString() == "InterNetwork")
                    {
                        ipv4Voices = _IPAddressVoices;
                    }
                }
                iConnectionCountVoices = 0;

                servVoices = new TcpServer(TCPLISTENPORTVoices, ipv4Voices);

                servVoices.Connected    += new TcpConnected(ConnectedVoices);
                servVoices.Disconnected += new TcpConnected(DisconnectedVoices);
                servVoices.DataReceived += new TcpReceive(ReceiveVoices);
                servVoices.Send         += new TcpSend(SendVoices);

                // Initialization succeeded.  Now, start serving up frames
                DoItVoices(m_Recorder, servVoices, sw);
            }
            catch (Exception ex)
            {
                try
                {
                    sw.WriteLine(String.Format("{0}: Failed on startup {1}", DateTime.Now.ToString(), ex));
                }
                catch { }
            }
            finally
            {
                // Cleanup
                if (servVoices != null)
                {
                    servVoices.Dispose();
                }


                sw.Close();
            }
        }