Beispiel #1
0
        public void startRecordServer(int codec, string m_pLoacalIP, int m_pLocalPort, string m_pRemoteIP, int m_pRemotePort, int m_pInDevicesselected)
        {
            try
            {
                if (m_pUdpServer != null)
                {
                    m_pUdpServer.Dispose();
                    m_pUdpServer = null;
                }

                if (m_pWaveIn != null)
                {
                    m_pWaveIn.Dispose();
                    m_pWaveIn = null;
                }


                m_Codec               = codec;
                m_pUdpServer          = new UdpServer();
                m_pUdpServer.Bindings = new IPEndPoint[] { new IPEndPoint(IPAddress.Parse(m_pLoacalIP), m_pLocalPort) };

                m_pUdpServer.Start();


                m_pTargetEP = new IPEndPoint(IPAddress.Parse(m_pRemoteIP), m_pRemotePort);

                m_pWaveIn             = new WaveIn(WaveIn.Devices[m_pInDevicesselected], 11025, 16, 1, 400);
                m_pWaveIn.BufferFull += new BufferFullHandler(m_pWaveIn_BufferFull);
                m_pWaveIn.Start();
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #2
0
 public void Stop()
 {
     IsRuning = false;
     UdpServer.Close();
     UdpServer.Dispose();
     UdpServer = null;
 }
Beispiel #3
0
        static void Test5()
        {
            if (_udpServer != null)
            {
                return;
            }

            _udpServer      = new UdpServer();
            _udpServer.Port = 888;
            //_udpServer.Received += _udpServer_Received;
            _udpServer.SessionTimeout = 5000;
            _udpServer.Open();

            var session = _udpServer.CreateSession(new IPEndPoint(IPAddress.Any, 0));

            for (int i = 0; i < 5; i++)
            {
                var buf = session.Receive();
                Console.WriteLine(buf.ToHex());
                session.Send("Hello");
            }

            //Console.ReadKey();
            _udpServer.Dispose();
            _udpServer = null;
        }
Beispiel #4
0
        private void m_pToggleRun_Click(object sender, EventArgs e)
        {
            if (m_IsRunning)
            {
                m_IsRunning = false;


                m_pUdpServer.Dispose();
                m_pUdpServer = null;

                m_pWaveOut.Dispose();
                m_pWaveOut = null;

                if (m_pRecordStream != null)
                {
                    m_pRecordStream.Dispose();
                    m_pRecordStream = null;
                }

                m_pTimer.Dispose();
                m_pTimer = null;


                m_pToggleRun.Text = "Bắt đầu lắng nghe";
            }
            else
            {
                if (m_pOutDevices.SelectedIndex == -1)
                {
                    MessageBox.Show(this, "Bạn hãy chọn thiết bị đầu ra !", "Lỗi:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (m_pRecord.Checked && m_pRecordFile.Text == "")
                {
                    MessageBox.Show(this, "Bạn hãy chọn tập tin đầu ra !", "Lối:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (m_pRecord.Checked)
                {
                    m_pRecordStream = File.Create(m_pRecordFile.Text);
                }

                m_IsRunning       = true;
                m_pToggleRun.Text = "Dừng lắng nghe";
                m_Codec           = m_pCodec.SelectedIndex;

                m_pWaveOut = new WaveOut(WaveOut.Devices[m_pOutDevices.SelectedIndex], 11025, 16, 1);

                m_pUdpServer                 = new UdpServer();
                m_pUdpServer.Bindings        = new IPEndPoint[] { new IPEndPoint(IPAddress.Parse(m_pLoacalIP.Text), (int)m_pLocalPort.Value) };
                m_pUdpServer.PacketReceived += new PacketReceivedHandler(m_pUdpServer_PacketReceived);
                m_pUdpServer.Start();



                m_pTimer.Enabled = true;
            }
        }
        public override void Dispose()
        {
            Logger.Debug("Disposing ServerManager");

            TcpServer?.Dispose();
            UdpServer?.Dispose();

            Logger.Debug("Disposed ServerManager");
        }
        private void stop(object sender, EventArgs e)
        {
            udpServer.Stop();
            udpServer.Dispose();

            //waveIn.Stop();
            //waveIn.Dispose();

            //waveOut.Dispose();
        }
Beispiel #7
0
 /// <summary>
 /// Releases unmanaged and - optionally - managed resources.
 /// </summary>
 /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
 protected virtual void Dispose(bool dispose)
 {
     if (dispose)
     {
         if (_udpServer != null)
         {
             _udpServer.Dispose();
         }
     }
 }
Beispiel #8
0
 public void LeaveConference()
 {
     if (InConference)
     {
         audioServer.Stop();
         audioServer.Dispose();
         audioWaveOut.Dispose();
         audioWaveIn.Dispose();
         InConference = false;
     }
 }
Beispiel #9
0
        /// <summary>
        /// Handles cleanup operations when app is cancelled or unloads
        /// </summary>
        public static Task WhenCancelled(CancellationToken cancellationToken)
        {
            if (udpServer != null)
            {
                udpServer.Dispose();
            }

            var tcs = new TaskCompletionSource <bool>();

            cancellationToken.Register(s => ((TaskCompletionSource <bool>)s).SetResult(true), tcs);
            return(tcs.Task);
        }
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected override void Dispose(bool dispose)
        {
            if (dispose)
            {
                if (UdpServer != null)
                {
                    UdpServer.Dispose();
                }
            }

            base.Dispose(dispose);
        }
Beispiel #11
0
        /// <summary>释放资源</summary>
        /// <param name="disposing"></param>
        protected override void OnDispose(Boolean disposing)
        {
            base.OnDispose(disposing);

            try
            {
                if (_Udp != null)
                {
                    _Udp.Dispose();
                }
            }
            catch { }
        }
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            _cancellationTokenSource.Cancel();
            _cancellationTokenSource.Dispose();
            _udpServer?.Dispose();
            _udpServer = null;

            _disposed = true;
        }
Beispiel #13
0
        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            base.OnClosing(e);
            running = false;
            MessageInfo offInfo = new MessageInfo {
                From = localInfo, MessageType = MessageInfo.Type.Sign, MessageSign = MessageInfo.Sign.Offline
            };

            if (broadcast != null)
            {
                broadcast.SendMessage(Serializable.SerializableToBytes(offInfo));
                broadcast.Dispose();
            }
            if (fileRequestListen != null)
            {
                fileRequestListen.Dispose();
            }
            if (fileThread != null)
            {
                fileThread.Abort();
            }
        }
Beispiel #14
0
        public void endlisten()
        {
            try
            {
                VUdpServer.Dispose();
                VUdpServer = null;

                VWaveOut.Dispose();
                VWaveOut = null;

                if (VRecordStream != null)
                {
                    VRecordStream.Dispose();
                    VRecordStream = null;
                }

                VTimer.Stop();
                endsend();
            }
            catch { }
            //VTimer = null;
        }
Beispiel #15
0
        private void m_pToggleRun_Click(object sender, EventArgs e)
        {
            if (m_IsRunning)
            {
                m_IsRunning     = false;
                m_IsSendingTest = false;

                m_pUdpServer.Dispose();
                m_pUdpServer = null;

                m_pWaveOut.Dispose();
                m_pWaveOut = null;

                if (m_pRecordStream != null)
                {
                    m_pRecordStream.Dispose();
                    m_pRecordStream = null;
                }

                m_pTimer.Dispose();
                m_pTimer = null;

                m_pInDevices.Enabled        = true;
                m_pOutDevices.Enabled       = true;
                m_pCodec.Enabled            = true;
                m_pToggleRun.Text           = "Start";
                m_pRecord.Enabled           = true;
                m_pRecordFile.Enabled       = true;
                m_pRecordFileBrowse.Enabled = true;
                m_pRemoteIP.Enabled         = false;
                m_pRemotePort.Enabled       = false;
                m_pToggleMic.Text           = "Start";
                m_pToggleMic.Enabled        = false;
                m_pSendTestSound.Enabled    = false;
                m_pSendTestSound.Text       = "Start";
                m_pPlayTestSound.Enabled    = false;
                m_pPlayTestSound.Text       = "Play";
            }
            else
            {
                if (m_pOutDevices.SelectedIndex == -1)
                {
                    MessageBox.Show(this, "Please select output device !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (m_pRecord.Checked && m_pRecordFile.Text == "")
                {
                    MessageBox.Show(this, "Please specify record file !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (m_pRecord.Checked)
                {
                    m_pRecordStream = File.Create(m_pRecordFile.Text);
                }

                m_IsRunning = true;

                m_Codec = m_pCodec.SelectedIndex;

                m_pWaveOut = new WaveOut(WaveOut.Devices[m_pOutDevices.SelectedIndex], 8000, 16, 1);

                m_pUdpServer                 = new UdpServer();
                m_pUdpServer.Bindings        = new IPEndPoint[] { new IPEndPoint(IPAddress.Parse(m_pLoacalIP.Text), (int)m_pLocalPort.Value) };
                m_pUdpServer.PacketReceived += new PacketReceivedHandler(m_pUdpServer_PacketReceived);
                m_pUdpServer.Start();

                m_pTimer          = new System.Windows.Forms.Timer();
                m_pTimer.Interval = 1000;
                m_pTimer.Tick    += new EventHandler(m_pTimer_Tick);
                m_pTimer.Enabled  = true;

                m_pInDevices.Enabled        = false;
                m_pOutDevices.Enabled       = false;
                m_pCodec.Enabled            = false;
                m_pToggleRun.Text           = "Stop";
                m_pRecord.Enabled           = false;
                m_pRecordFile.Enabled       = false;
                m_pRecordFileBrowse.Enabled = false;
                m_pRemoteIP.Enabled         = true;
                m_pRemotePort.Enabled       = true;
                m_pToggleMic.Enabled        = true;
                m_pSendTestSound.Enabled    = true;
                m_pSendTestSound.Text       = "Start";
                m_pPlayTestSound.Enabled    = true;
                m_pPlayTestSound.Text       = "Play";
            }
        }