实验十
实验目的
具备计算机网络环境下音频通信系统的设计能力
掌握音频采集和播放、音频往后
预习内容
基于多媒体控件的音频播放编程技术
基于DirectX的音频采集与播放编程技术
基于低级音频函数的音频采集与播放编程技术
音频网络全双工通信编程技术
实验内容
实现IP电话通信
实验结果
using System;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.DirectX.DirectSound;
namespace IP电话程序设计
{
public partial class Form1 : Form
{
string myname = "cuizhaowen";
Socket chatsock;
Thread chatthread;
public Form1()
{
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
}
private void button1_Click(object sender, EventArgs e)
{
if (this.chatsock != null)
{
DialogResult result =MessageBox.Show("你现在处于聊天中,是否断开当前连接进行新连接? /n", "请求连接",MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
this.chatthread.Abort();
this.chatsock.Close();
this.chatsock = null;
}
}
if (this.chatsock == null)
{
try
{
IPEndPoint riep = new IPEndPoint(IPAddress.Parse(this.tbIP.Text), 8061);
this.chatsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
this.chatsock.Connect(riep);
TransData.SendVarData(this.chatsock, System.Text.Encoding.Unicode.GetBytes("wantConnect|" + this.myname));
string answerBack = System.Text.Encoding.Unicode.GetString(TransData.ReceiveVarData(this.chatsock));
if (answerBack == "yes")
{
this.chatthread = new Thread(new ThreadStart(chat));
this.chatthread.Start();
}
else
{