资源简介
用C#写的点对点聊天程序,采用udp编写,里面有源码和程序,
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace myQQQ
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object senders EventArgs e)
{
try
{
//构建UDP服务器
//设置服务IP,设置UDP端口号
ipep = new IPEndPoint(IPAddress.Parse(textBox1.Text) int.Parse(textBox2.Text));
//定义网络类型,数据连接类型和网络协议UDP
server = new Socket(AddressFamily.InterNetwork SocketType.Dgram ProtocolType.Udp);
Thread th = new Thread(new ThreadStart(myListen));
th.IsBackground = true;
th.Start();
button2.Enabled = false;
textBox1.Enabled = textBox2.Enabled = textBox3.Enabled = false;
button1.Enabled = true;
}
catch (Exception e2)
{
MessageBox.Show(“请正确填写!“);
}
}
Socket server;
IPEndPoint ipep;
private void myListen()
{
IPEndPoint sender = new IPEndPoint(IPAddress.Any 0);
EndPoint Remote = (EndPoint)sender;
while (true)
{
if (ena)
{
byte[] data = new byte[1024];
int recv = server.ReceiveFrom(data ref Remote);
richTextBox1.AppendText(Encoding.Default.GetString(data));
}
}
}
private void button1_Click(object sender EventArgs e)
{
byte[] b = Encoding.Default.GetBytes(textBox3.Text + “:\n“ + textBox7.Text+“\n“);
server.SendTo(b b.Length SocketFlags.None ipep);
richTextBox1.AppendText(textBox3.Text + “:\n“ + textBox7.Text + “\n“);
ena = true;
}
bool ena = false;
IPEndPoint ipep2;
Socket newsock2;
private void button3_Click(object sender EventArgs e)
{
try
{
//构建UDP服务器
//得到本机IP,设置UDP端口号
ipep2 = new IPEndPoint(IPAddress.Any int.Parse(textBox9.Text));
newsock2 = new Socket(AddressFamily.InterNetwork SocketType.Dgram ProtocolType.Udp);
//绑定网络地址
newsock2.Bind(ipep2);
Thread thread = new Thread(new ThreadStart(serverListen));
thread.IsBackground = true;
thread.Start();
button3.Enabled = textBox6.Enabled = textBox9.Enabled = false;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 14336 2012-04-06 13:13 myQQQ\myQQQ\bin\Debug\myQQQ.exe
文件 28160 2012-04-06 13:13 myQQQ\myQQQ\bin\Debug\myQQQ.pdb
文件 11600 2012-04-06 13:22 myQQQ\myQQQ\bin\Debug\myQQQ.vshost.exe
文件 490 2009-08-31 00:40 myQQQ\myQQQ\bin\Debug\myQQQ.vshost.exe.manifest
文件 4271 2012-04-06 13:13 myQQQ\myQQQ\Form1.cs
文件 15373 2012-04-06 12:22 myQQQ\myQQQ\Form1.Designer.cs
文件 5817 2012-04-06 12:22 myQQQ\myQQQ\Form1.resx
文件 3669 2012-04-06 12:30 myQQQ\myQQQ\myQQQ.csproj
文件 6172 2012-04-06 13:13 myQQQ\myQQQ\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 184 2012-04-06 12:30 myQQQ\myQQQ\obj\x86\Debug\GenerateResource.read.1.tlog
文件 458 2012-04-06 12:30 myQQQ\myQQQ\obj\x86\Debug\GenerateResource.write.1.tlog
文件 541 2012-04-06 13:22 myQQQ\myQQQ\obj\x86\Debug\myQQQ.csproj.FileListAbsolute.txt
文件 14336 2012-04-06 13:13 myQQQ\myQQQ\obj\x86\Debug\myQQQ.exe
文件 180 2012-04-06 12:30 myQQQ\myQQQ\obj\x86\Debug\myQQQ.Form1.resources
文件 28160 2012-04-06 13:13 myQQQ\myQQQ\obj\x86\Debug\myQQQ.pdb
文件 180 2012-04-06 12:30 myQQQ\myQQQ\obj\x86\Debug\myQQQ.Properties.Resources.resources
文件 486 2012-04-06 11:39 myQQQ\myQQQ\Program.cs
文件 1356 2012-04-06 11:39 myQQQ\myQQQ\Properties\AssemblyInfo.cs
文件 2860 2012-04-06 11:39 myQQQ\myQQQ\Properties\Resources.Designer.cs
文件 5612 2012-04-06 11:39 myQQQ\myQQQ\Properties\Resources.resx
文件 1090 2012-04-06 11:39 myQQQ\myQQQ\Properties\Settings.Designer.cs
文件 249 2012-04-06 11:39 myQQQ\myQQQ\Properties\Settings.settings
文件 857 2012-04-06 11:40 myQQQ\myQQQ.sln
..A..H. 17920 2012-04-06 13:40 myQQQ\myQQQ.suo
目录 0 2012-04-06 11:39 myQQQ\myQQQ\obj\x86\Debug\TempPE
目录 0 2012-04-06 13:13 myQQQ\myQQQ\obj\x86\Debug
目录 0 2012-04-06 12:30 myQQQ\myQQQ\bin\Debug
目录 0 2012-04-06 11:39 myQQQ\myQQQ\obj\x86
目录 0 2012-04-06 11:39 myQQQ\myQQQ\bin
目录 0 2012-04-06 11:39 myQQQ\myQQQ\obj
............此处省略6个文件信息
评论
共有 条评论