我想使用任何协议使用外部IP通过互联网进行语音聊天,但使用外部IP和使用c#的本地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
答案 0 :(得分:0)
如果您唯一的问题是在两个IP地址之间联网数据,那么您应该只关注网络部分。您想直接使用WCF还是TCP?在第二种情况下,System.Net.Sockets命名空间具有类,如TcpClient,TcpListener,UdpClient ......