简体   繁体   中英

how to make voice chat using external ip c#

I want to make voice chat using external ip over Internet using any protocol but using external ip and local ip using c# I have no problem in voice just my problem how to send and receive buffer

private Socket r;
private Thread t;
r = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
t = new Thread(new ThreadStart(Voice_In));
#region Voice_In()
        private void Voice_In()
        {
            byte[] br;
            r.Bind(new IPEndPoint(IPAddress.Any, int.Parse(this.textBox2.Text)));
            while (true)
            {
                br = new byte[16384];
                r.Receive(br);
                m_Fifo.Write(br, 0, br.Length);
            }
        }
        #endregion
        #region Voice_Out()

        private void Voice_Out(IntPtr data, int size)
        {
            //for Recorder
            if (m_RecBuffer == null || m_RecBuffer.Length < size)
                m_RecBuffer = new byte[size];
            System.Runtime.InteropServices.Marshal.Copy(data, m_RecBuffer, 0, size);
            //Microphone ==> data ==> m_RecBuffer ==> m_Fifo
            r.SendTo(m_RecBuffer, new IPEndPoint(IPAddress.Parse(this.textBox1.Text), int.Parse(this.textBox3.Text)));
        }  

        #endregion

Well if your only issue is to network data between two ip addresses, you should just focus on the network part. Do you want to use WCF or TCP directly? In the second case, System.Net.Sockets namespace has classes like TcpClient, TcpListener, UdpClient...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM