如何使用外部IP C#进行语音聊天
我想使用任何协议通过互联网使用外部 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您唯一的问题是在两个 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...