如何使用外部IP C#进行语音聊天

发布于 2024-10-19 21:56:57 字数 1173 浏览 10 评论 0原文

我想使用任何协议通过互联网使用外部 IP 进行语音聊天,但使用 C# 使用外部 IP 和本地 IP 我的语音没有问题,只是我的问题如何发送和接收缓冲区

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑梦风尘 2024-10-26 21:56:57

如果您唯一的问题是在两个 IP 地址之间传输网络数据,那么您应该只关注网络部分。你想直接使用WCF还是TCP?在第二种情况下,System.Net.Sockets 命名空间具有 TcpClient、TcpListener、UdpClient 等类...

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文