资源简介
用c#写了一个比较健壮的多人聊天室 可以多个人一起聊天

代码片段和文件信息
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.Threading;
using System.Net.Sockets;
namespace 客户端
{
public partial class Form1 : Form
{
Socket lian;
public Form1()
{
InitializeComponent();
}
///
/// 不停接收信息的线程
///
void jieshou()
{
while (true)
{
Byte[] buff = new Byte[1000];
try
{
int s = lian.Receive(buff);
if (s == 0)
break;
string str = Encoding.UTF8.GetString(buff 0 s);
this.Invoke(new Action(() =>
{
this.neirong.AppendText(str + “\r\n“);
}));
}
catch { }
}
}
///
/// 发送消息
///
///
///
private void button1_Click(object sender EventArgs e)
{
if (this.button2.Text != “关闭“)
{
MessageBox.Show(“请先连接“);
return;
}
string str = this.liaotian.Text;
string strr = this.name.Text + “:“ + str;
byte[] buf = Encoding.UTF8.GetBytes(strr);
try
{
lian.Send(buf);
}
catch
{
//服务器关闭 或者发生异常 断开连接
lian.Close();
MessageBox.Show(“请重新连接“);
this.button2.Text = “连接“;
return;
}
this.liaotian.Clear();
this.neirong.AppendText(“我:“ + str + “\r\n“);
}
///
/// 点第一次连接 第二次关闭连接
///
///
///
private void button2_Click(object sender EventArgs e)
{
if (this.button2.Text == “关闭“)
{
lian.Close();
this.button2.Text = “连接“;
return;
}
try
{
//创建负责通信的Socket
lian = new Socket(AddressFamily.InterNetwork SocketType.Stream ProtocolType.Tcp);
IPAddress ip = IPAddress.Parse(“127.0.0.1“);
IPEndPoint point = new IPEndPoint(ip 3333);
//获得要连接的远程服务器应用程序的IP地址和端口号
lian.Connect(point);
//开启一个新的线程不停的接收服务端发来的消息
Thread t = new Thread(jieshou);
t.IsBackground = true;
t.Start();
this.button2.Text = “关闭“;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10752 2017-08-20 17:34 聊天室\客户端\bin\Debug\客户端.exe
文件 26112 2017-08-20 17:34 聊天室\客户端\bin\Debug\客户端.pdb
文件 14328 2017-08-20 17:32 聊天室\客户端\bin\Debug\客户端.vshost.exe
文件 490 2009-06-11 05:14 聊天室\客户端\bin\Debug\客户端.vshost.exe.manifest
文件 3324 2017-08-20 17:34 聊天室\客户端\Form1.cs
文件 5089 2017-08-20 14:39 聊天室\客户端\Form1.Designer.cs
文件 5814 2017-08-20 14:39 聊天室\客户端\Form1.resx
文件 722 2017-08-20 17:32 聊天室\客户端\obj\Debug\客户端.csproj.FileListAbsolute.txt
文件 847 2017-08-20 14:39 聊天室\客户端\obj\Debug\客户端.csproj.GenerateResource.Cache
文件 10752 2017-08-20 17:34 聊天室\客户端\obj\Debug\客户端.exe
文件 180 2017-08-20 14:39 聊天室\客户端\obj\Debug\客户端.Form1.resources
文件 26112 2017-08-20 17:34 聊天室\客户端\obj\Debug\客户端.pdb
文件 180 2017-08-19 16:09 聊天室\客户端\obj\Debug\客户端.Properties.Resources.resources
文件 490 2017-08-19 15:53 聊天室\客户端\Program.cs
文件 1350 2017-08-19 15:53 聊天室\客户端\Properties\AssemblyInfo.cs
文件 2868 2017-08-19 15:53 聊天室\客户端\Properties\Resources.Designer.cs
文件 5612 2017-08-19 15:53 聊天室\客户端\Properties\Resources.resx
文件 1094 2017-08-19 15:53 聊天室\客户端\Properties\Settings.Designer.cs
文件 249 2017-08-19 15:53 聊天室\客户端\Properties\Settings.settings
文件 3764 2017-08-19 16:09 聊天室\客户端\客户端.csproj
文件 10752 2017-08-20 15:12 聊天室\聊天室\bin\Debug\聊天室.exe
文件 28160 2017-08-20 15:12 聊天室\聊天室\bin\Debug\聊天室.pdb
文件 14328 2017-08-19 16:10 聊天室\聊天室\bin\Debug\聊天室.vshost.exe
文件 490 2009-06-11 05:14 聊天室\聊天室\bin\Debug\聊天室.vshost.exe.manifest
文件 4855 2017-08-20 15:12 聊天室\聊天室\Form1.cs
文件 4361 2017-08-19 17:27 聊天室\聊天室\Form1.Designer.cs
文件 5814 2017-08-19 17:27 聊天室\聊天室\Form1.resx
文件 722 2017-08-20 15:01 聊天室\聊天室\obj\Debug\聊天室.csproj.FileListAbsolute.txt
文件 847 2017-08-19 17:27 聊天室\聊天室\obj\Debug\聊天室.csproj.GenerateResource.Cache
文件 10752 2017-08-20 15:12 聊天室\聊天室\obj\Debug\聊天室.exe
............此处省略32个文件信息
相关资源
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
评论
共有 条评论