Example #1
0
        /// <summary>
        /// Init
        /// </summary>
        /// <param name="bitsPerSample"></param>
        /// <param name="channels"></param>
        public void Init(ServerThread st, string soundDeviceName, int samplesPerSecond, int bitsPerSample, int channels, int soundBufferCount, uint jitterBufferCount, uint jitterBufferMilliseconds)
        {
            //Werte übernehmen
            this.ServerThread             = st;
            this.SamplesPerSecond         = samplesPerSecond;
            this.BitsPerSample            = bitsPerSample;
            this.Channels                 = channels;
            this.SoundBufferCount         = soundBufferCount;
            this.JitterBufferCount        = jitterBufferCount;
            this.JitterBufferMilliseconds = jitterBufferMilliseconds;

            //Player
            this.Player = new WinSound.Player();
            this.Player.Open(soundDeviceName, samplesPerSecond, bitsPerSample, channels, soundBufferCount);

            //Wenn ein JitterBuffer verwendet werden soll
            if (jitterBufferCount >= 2)
            {
                //Neuen JitterBuffer erstellen
                this.JitterBuffer = new WinSound.JitterBuffer(this.Player, jitterBufferCount, jitterBufferMilliseconds);
                this.JitterBuffer.DataAvailable += new WinSound.JitterBuffer.DelegateDataAvailable(OnJitterBufferDataAvailable);
                this.JitterBuffer.Start();
            }

            //Protocol
            this.Protocol = new WinSound.Protocol(WinSound.ProtocolTypes.LH, Encoding.Default);
            this.Protocol.DataComplete += new WinSound.Protocol.DelegateDataComplete(OnProtocolDataComplete);


            //Initialisiert
            IsInitialized = true;
        }
Example #2
0
 /// <summary>
 /// OnServerClientDisconnected
 /// </summary>
 /// <param name="st"></param>
 /// <param name="info"></param>
 private void OnServerClientDisconnected(ServerThread st, string info)
 {
     try
     {
         //Wenn vorhanden
         if (m_DictionaryServerDatas.ContainsKey(st))
         {
             //Alle Daten freigeben
             ServerThreadData data = m_DictionaryServerDatas[st];
             data.Dispose();
             lock (LockerDictionary)
             {
                 //Entfernen
                 m_DictionaryServerDatas.Remove(st);
             }
             //Aus FlowLayoutPanels entfernen
             RemoveServerClientToFlowLayoutPanel_ServerClient(st);
             RemoveServerClientToFlowLayoutPanel_ServerProgressBar(data);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Example #3
0
        /// <summary>
        /// Init
        /// </summary>
        /// <param name="bitsPerSample"></param>
        /// <param name="channels"></param>
        public void Init(ServerThread st, string soundDeviceName, int samplesPerSecond, int bitsPerSample, int channels, int soundBufferCount, uint jitterBufferCount, uint jitterBufferMilliseconds)
        {
            //Werte übernehmen
            this.ServerThread = st;
            this.SamplesPerSecond = samplesPerSecond;
            this.BitsPerSample = bitsPerSample;
            this.Channels = channels;
            this.SoundBufferCount = soundBufferCount;
            this.JitterBufferCount = jitterBufferCount;
            this.JitterBufferMilliseconds = jitterBufferMilliseconds;

            //Player
            this.Player = new WinSound.Player();
            this.Player.Open(soundDeviceName, samplesPerSecond, bitsPerSample, channels, soundBufferCount);

            //Wenn ein JitterBuffer verwendet werden soll
            if (jitterBufferCount >= 2)
            {
                //Neuen JitterBuffer erstellen
                this.JitterBuffer = new WinSound.JitterBuffer(this.Player, jitterBufferCount, jitterBufferMilliseconds);
                this.JitterBuffer.DataAvailable += new WinSound.JitterBuffer.DelegateDataAvailable(OnJitterBufferDataAvailable);
                this.JitterBuffer.Start();
            }

            //Protocol
            this.Protocol = new WinSound.Protocol(WinSound.ProtocolTypes.LH, Encoding.Default);
            this.Protocol.DataComplete += new WinSound.Protocol.DelegateDataComplete(OnProtocolDataComplete);

            //Initialisiert
            IsInitialized = true;
        }
Example #4
0
 /// <summary>
 /// Wird ausgeführt wenn Daten angekommen sind
 /// </summary>
 /// <param name="Data"></param>
 private void OnDataReceived(ServerThread st, Byte[] data)
 {
     //Event abschicken bzw. weiterleiten
     if (DataReceived != null)
     {
         DataReceived(st, data);
     }
 }
Example #5
0
        /// <summary>
        /// Wird aufgerufen wenn sich ein Client beendet
        /// </summary>
        /// <param name="st"></param>
        private void OnClientDisconnected(ServerThread st, string info)
        {
            //Aus Liste entfernen
            m_threads.Remove(st);

            //Event abschicken bzw. weiterleiten
            if (ClientDisconnected != null)
            {
                ClientDisconnected(st, info);
            }
        }
Example #6
0
 /// <summary>
 /// OnServerDataReceiced
 /// </summary>
 /// <param name="st"></param>
 /// <param name="data"></param>
 private void OnServerDataReceiced(ServerThread st, Byte[] data)
 {
     //Wenn vorhanden
     if (m_DictionaryServerDatas.ContainsKey(st))
     {
         //Wenn Protocol
         ServerThreadData stData = m_DictionaryServerDatas[st];
         if (stData.Protocol != null)
         {
             stData.Protocol.Receive_LH(st, data);
         }
     }
 }
Example #7
0
 /// <summary>
 /// AddServerClientToFlowLayoutPanel_ServerClient
 /// </summary>
 /// <param name="st"></param>
 private void AddServerClientToFlowLayoutPanel_ServerClient(ServerThread st)
 {
     try
     {
         listBoxClients.Dispatcher.Invoke(new Action(() =>
         {
             listBoxClients.Items.Add(st.Client.Client.RemoteEndPoint.ToString());
         }));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Example #8
0
 private void RemoveServerClientToFlowLayoutPanel_ServerClient(ServerThread st)
 {
     try
     {
         listBoxClients.Dispatcher.Invoke(new Action(() =>
         {
             listBoxClients.Items.Remove(st.Client.Client.RemoteEndPoint.ToString());
         }));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Example #9
0
        /// <summary>
        /// Wird aufgerufen wenn sich ein Client verbindet
        /// </summary>
        /// <param name="st"></param>
        private void OnClientConnected(ServerThread st)
        {
            //Wenn nicht vorhanden
            if (!m_threads.Contains(st))
            {
                //Zur Liste der Clients hinzufügen
                m_threads.Add(st);
            }

            //Event abschicken bzw. weiterleiten
            if (ClientConnected != null)
            {
                ClientConnected(st);
            }
        }
Example #10
0
        /// <summary>
        /// Beenden des Servers
        /// </summary>
        public void Stop()
        {
            try
            {
                if (m_ThreadMainServer != null)
                {
                    // Haupt-TCPServer-Thread stoppen
                    m_ThreadMainServer.Abort();
                    System.Threading.Thread.Sleep(100);
                }

                // Alle TCPServer-Threads stoppen
                for (IEnumerator en = m_threads.GetEnumerator(); en.MoveNext();)
                {
                    //Nächsten TCPServer-Thread holen
                    ServerThread st = (ServerThread)en.Current;
                    //und stoppen
                    st.Stop();

                    //Event abschicken
                    if (ClientDisconnected != null)
                    {
                        ClientDisconnected(st, "Verbindung wurde beendet");
                    }
                }

                if (m_tcpip != null)
                {
                    //Listener stoppen
                    m_tcpip.Stop();
                    m_tcpip.Server.Close();
                }

                //Liste leeren
                m_threads.Clear();
                //Status vermerken
                this.m_State = ListenerState.Stopped;
            }
            catch (Exception)
            {
                this.m_State = ListenerState.Error;
            }
        }
Example #11
0
 /// <summary>
 /// OnServerClientConnected
 /// </summary>
 /// <param name="st"></param>
 private void OnServerClientConnected(ServerThread st)
 {
     try
     {
         //ServerThread Daten erstellen
         ServerThreadData data = new ServerThreadData();
         //Initialisieren
         //data.Init(st, m_Config.SoundDeviceNameServer, 8000, 16, 1, 8, 20, 20);
         //Hinzufügen
         m_DictionaryServerDatas[st] = data;
         //Zu FlowLayoutPanels hinzufügen
         AddServerClientToFlowLayoutPanel_ServerClient(st);
         AddServerClientToFlowLayoutPanel_ServerProgressBars(data);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Example #12
0
        /// <summary>
        /// Run
        /// </summary>
        private void Run()
        {
            while (true)
            {
                //Wartet auf eingehenden Verbindungswunsch
                TcpClient client = m_tcpip.AcceptTcpClient();
                //Initialisiert und startet einen TCPServer-Thread
                //und fügt ihn zur Liste der TCPServer-Threads hinzu
                ServerThread st = new ServerThread(client);

                //Events hinzufügen
                st.DataReceived       += new ServerThread.DelegateDataReceived(OnDataReceived);
                st.ClientDisconnected += new ServerThread.DelegateClientDisconnected(OnClientDisconnected);

                //Weitere Arbeiten
                OnClientConnected(st);

                //Beginnen zu lesen
                client.Client.BeginReceive(st.ReadBuffer, 0, st.ReadBuffer.Length, SocketFlags.None, st.Receive, client.Client);
            }
        }
Example #13
0
        /// <summary>
        /// Run
        /// </summary>
        private void Run()
        {
            while (true)
            {
                //Wartet auf eingehenden Verbindungswunsch
                TcpClient client = m_tcpip.AcceptTcpClient();
                //Initialisiert und startet einen TCPServer-Thread
                //und fügt ihn zur Liste der TCPServer-Threads hinzu
                ServerThread st = new ServerThread(client);

                //Events hinzufügen
                st.DataReceived += new ServerThread.DelegateDataReceived(OnDataReceived);
                st.ClientDisconnected += new ServerThread.DelegateClientDisconnected(OnClientDisconnected);

                //Weitere Arbeiten
                OnClientConnected(st);

                //Beginnen zu lesen
                client.Client.BeginReceive(st.ReadBuffer, 0, st.ReadBuffer.Length, SocketFlags.None, st.Receive, client.Client);
            }
        }
Example #14
0
 /// <summary>
 /// Wird ausgeführt wenn Daten angekommen sind
 /// </summary>
 /// <param name="Data"></param>
 private void OnDataReceived(ServerThread st, Byte[] data)
 {
     //Event abschicken bzw. weiterleiten
     if (DataReceived != null)
     {
         DataReceived(st, data);
     }
 }
Example #15
0
        /// <summary>
        /// Wird aufgerufen wenn sich ein Client beendet
        /// </summary>
        /// <param name="st"></param>
        private void OnClientDisconnected(ServerThread st, string info)
        {
            //Aus Liste entfernen
            m_threads.Remove(st);

            //Event abschicken bzw. weiterleiten
            if (ClientDisconnected != null)
            {
                ClientDisconnected(st, info);
            }
        }
Example #16
0
        /// <summary>
        /// Wird aufgerufen wenn sich ein Client verbindet
        /// </summary>
        /// <param name="st"></param>
        private void OnClientConnected(ServerThread st)
        {
            //Wenn nicht vorhanden
            if (!m_threads.Contains(st))
            {
                //Zur Liste der Clients hinzufügen
                m_threads.Add(st);
            }

            //Event abschicken bzw. weiterleiten
            if (ClientConnected != null)
            {
                ClientConnected(st);
            }
        }
Example #17
0
 /// <summary>
 /// OnServerDataReceiced
 /// </summary>
 /// <param name="st"></param>
 /// <param name="data"></param>
 private void OnServerDataReceiced(ServerThread st, Byte[] data)
 {
     //Wenn vorhanden
     if (m_DictionaryServerDatas.ContainsKey(st))
     {
         //Wenn Protocol
         ServerThreadData stData = m_DictionaryServerDatas[st];
         if (stData.Protocol != null)
         {
             stData.Protocol.Receive_LH(st, data);
         }
     }
 }
Example #18
0
 /// <summary>
 /// OnServerClientDisconnected
 /// </summary>
 /// <param name="st"></param>
 /// <param name="info"></param>
 private void OnServerClientDisconnected(ServerThread st, string info)
 {
     try
     {
         //Wenn vorhanden
         if (m_DictionaryServerDatas.ContainsKey(st))
         {
             //Alle Daten freigeben
             ServerThreadData data = m_DictionaryServerDatas[st];
             data.Dispose();
             lock (LockerDictionary)
             {
                 //Entfernen
                 m_DictionaryServerDatas.Remove(st);
             }
             //Aus FlowLayoutPanels entfernen
             RemoveServerClientToFlowLayoutPanel_ServerClient(st);
             RemoveServerClientToFlowLayoutPanel_ServerProgressBar(data);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Example #19
0
 /// <summary>
 /// OnServerClientConnected
 /// </summary>
 /// <param name="st"></param>
 private void OnServerClientConnected(ServerThread st)
 {
     try
     {
         //ServerThread Daten erstellen
         ServerThreadData data = new ServerThreadData();
         //Initialisieren
         //data.Init(st, m_Config.SoundDeviceNameServer, 8000, 16, 1, 8, 20, 20);
         //Hinzufügen
         m_DictionaryServerDatas[st] = data;
         //Zu FlowLayoutPanels hinzufügen
         AddServerClientToFlowLayoutPanel_ServerClient(st);
         AddServerClientToFlowLayoutPanel_ServerProgressBars(data);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }