基本信息
源码名称:C# 点对点聊天
源码大小:1.27M
文件格式:.rar
开发语言:C#
更新时间:2017-03-12
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Threading;
using System.Net;
using System.Net.Sockets;
namespace MatureVoice
{
public partial class Voice : DevComponents.DotNetBar.Office2007Form
{
public Voice()
{
InitializeComponent();
}
private Point posMouse;
private NetChat netchat1;
private void Voice_Load(object sender, EventArgs e)
{
netchat1 = new NetChat(8000);
this.Text = "本机:" netchat1.BindSelf(netchat1.LocalIPEnd);
this.comboIP.Text = Dns.GetHostAddresses(Dns.GetHostName())[0].ToString();
}
private void Voice_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
posMouse.X = e.X;
posMouse.Y = e.Y;
}
}
private void Voice_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Voice.ActiveForm.Top = Control.MousePosition.Y - posMouse.Y - SystemInformation.FrameBorderSize.Height - SystemInformation.CaptionHeight;
Voice.ActiveForm.Left = Control.MousePosition.X - posMouse.X - SystemInformation.FrameBorderSize.Width;
}
}
private void btnSelect_Click(object sender, EventArgs e)
{
FormWrite("正在查找局域网内主机,请稍后...");
Form2 frm2 = new Form2();
if (frm2.ShowDialog() == DialogResult.OK)
{
comboIP.Text = frm2.IPAdd;
FormWrite("已经找到可用主机");
}
else
{
FormWrite("没有找到合适的主机...");
}
frm2.Close();
}
//建立一个委托
private delegate void FormHandel(string strArgu);
private void FormWrite(string strText)
{
if (InvokeRequired)
{
FormHandel handel1 = new FormHandel(FormWrite);
this.Invoke(handel1, new object[] { strText });
}
else
{
lblStatus.Text = strText;
}
}
private void Voice_FormClosing(object sender, FormClosingEventArgs e)
{
}
private void lblStatus_TextChanged(object sender, EventArgs e)
{
timer1.Start();
}
private int intTickedTimes = 0;
private void timer1_Tick(object sender, EventArgs e)
{
intTickedTimes ;
if (intTickedTimes > 6)
{
timer1.Stop();
intTickedTimes = 0;
}
else
{
lblStatus.ForeColor = intTickedTimes % 2 == 0 ? Color.MidnightBlue : Color.Red;
}
}
private void btnSubmit_Click(object sender, EventArgs e)
{
try
{
netchat1.SetRemoteIPEnd(comboIP.Text, 8000);
btnChat.Enabled = true;
FormWrite("本机已经准备就绪!");
}
catch
{
FormWrite("出错了,IP地址非法");
btnChat.Enabled = false;
}
}
private void btnChat_Click(object sender, EventArgs e)
{//先初始化语音模块,启动监听方法,再启动语音采集方法
if (btnChat.Text == "开始语聊")
{
btnChat.Text = "停止语聊";
btnSelect.Enabled = false;
btnSubmit.Enabled = false;
try
{
netchat1.Intptr = this.Handle;
netchat1.InitVoice();
//Console.WriteLine(netchat1);
}
catch
{
FormWrite("声音模块初始化失败");
}
try
{
netchat1.Listen();
}
catch
{
FormWrite("监听模块异常");
}
try
{
netchat1.StartSendVoice();
}
catch
{
if (MessageBox.Show("应用程序出现问题,需要重新启动应该程序嘛?", "系统提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
{
Application.Exit();//先关闭应用程序
System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
}
}
}
else
{
netchat1.Stop();
btnChat.Text = "开始语聊";
btnSelect.Enabled = true;
btnSubmit.Enabled = true;
}
}
}
}