资源简介
用c#实现的tcp局域网聊天程序,用到了NetworkStream,tcpclient,tcplistener等这些类实现,程序中还有状态栏,可是显示当先状态!
另外还增加了对异常的处理,使程序更加健壮!!!

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace MyTcpClient
{
public partial class Form1 : Form
{
private bool isExit = false;
System.Collections.ArrayList clientlist = new System.Collections.ArrayList();
TcpListener listener;
private delegate void SetListBoxCallBack(string str);
private SetListBoxCallBack setlistcallback;
private delegate void SetRichTextBoxCallBack(string str);
private SetRichTextBoxCallBack setRichTextBoxCallBack;
private delegate void SetComboBoxCallBack(string str);
private SetComboBoxCallBack setComboBoxCallBack;
private delegate void RemoveComboBoxItemsCallBack(DataReadWrite datareadwrite);
private RemoveComboBoxItemsCallBack removecomboboxcallback;
private ManualResetEvent allDone = new ManualResetEvent(false);
public Form1()
{
InitializeComponent();
setlistcallback = new SetListBoxCallBack(SetListBox);
setRichTextBoxCallBack = new SetRichTextBoxCallBack(SetReceiveText);
setComboBoxCallBack = new SetComboBoxCallBack(SetComboBox);
removecomboboxcallback = new RemoveComboBoxItemsCallBack(RemoveComboBoxItems);
}
private void buttonstart_Click(object sender EventArgs e)
{
Thread myThread=new Thread(new ThreadStart(AcceptConnection));
myThread.Start();
buttonstart.Enabled=false;
buttonstop.Enabled=true;
}
private void AcceptConnection()
{
IPAddress[] ip = Dns.GetHostAddresses(Dns.GetHostName());
listener = new TcpListener(ip[0] 9001);
listener.Start();
while (isExit == false)
{
try
{
allDone.Reset();
AsyncCallback callback = new AsyncCallback(AcceptTcpClientCallBack);
listBoxStatus.Invoke(setlistcallback “开始等待连接“);
listener.BeginAcceptTcpClient(callback listener);
allDone.WaitOne();
}
catch (Exception e)
{
listBoxStatus.Invoke(setlistcallback e.Message);
break;
}
finally
{
}
}
}
private void AcceptTcpClientCallBack(IAsyncResult iar)
{
try
{
TcpListener listener = (TcpListener)iar.AsyncState;
TcpClient client = listener.EndAcceptTcpClient(iar);
listBoxStatus.Invoke(setlistcallback “已接收客户连接:“ + client.Client.RemoteEndPoint);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 24576 2009-03-01 19:25 tcp聊天程序\MyTcpClient\MyTcpClient\bin\Debug\MyTcpClient.exe
文件 28160 2009-03-01 19:25 tcp聊天程序\MyTcpClient\MyTcpClient\bin\Debug\MyTcpClient.pdb
文件 5632 2005-11-11 22:25 tcp聊天程序\MyTcpClient\MyTcpClient\bin\Debug\MyTcpClient.vshost.exe
文件 7914 2009-03-01 19:17 tcp聊天程序\MyTcpClient\MyTcpClient\Form1.cs
文件 8455 2009-03-01 18:28 tcp聊天程序\MyTcpClient\MyTcpClient\Form1.Designer.cs
文件 5814 2009-03-01 18:28 tcp聊天程序\MyTcpClient\MyTcpClient\Form1.resx
文件 3229 2009-03-01 18:28 tcp聊天程序\MyTcpClient\MyTcpClient\MyTcpClient.csproj
文件 842 2009-03-01 19:25 tcp聊天程序\MyTcpClient\MyTcpClient\obj\Debug\MyTcpClient.csproj.GenerateResource.Cache
文件 24576 2009-03-01 19:25 tcp聊天程序\MyTcpClient\MyTcpClient\obj\Debug\MyTcpClient.exe
文件 180 2009-03-01 19:25 tcp聊天程序\MyTcpClient\MyTcpClient\obj\Debug\MyTcpClient.Form1.resources
文件 28160 2009-03-01 19:25 tcp聊天程序\MyTcpClient\MyTcpClient\obj\Debug\MyTcpClient.pdb
文件 180 2009-03-01 19:25 tcp聊天程序\MyTcpClient\MyTcpClient\obj\Debug\MyTcpClient.Properties.Resources.resources
文件 296 2009-03-01 19:26 tcp聊天程序\MyTcpClient\MyTcpClient\obj\MyTcpClient.csproj.FileList.txt
文件 470 2009-03-01 16:55 tcp聊天程序\MyTcpClient\MyTcpClient\Program.cs
文件 1206 2009-03-01 16:55 tcp聊天程序\MyTcpClient\MyTcpClient\Properties\AssemblyInfo.cs
文件 2877 2009-03-01 16:55 tcp聊天程序\MyTcpClient\MyTcpClient\Properties\Resources.Designer.cs
文件 5612 2009-03-01 16:55 tcp聊天程序\MyTcpClient\MyTcpClient\Properties\Resources.resx
文件 1095 2009-03-01 16:55 tcp聊天程序\MyTcpClient\MyTcpClient\Properties\Settings.Designer.cs
文件 249 2009-03-01 16:55 tcp聊天程序\MyTcpClient\MyTcpClient\Properties\Settings.settings
文件 922 2009-03-01 16:55 tcp聊天程序\MyTcpClient\MyTcpClient.sln
..A..H. 12288 2009-03-01 19:27 tcp聊天程序\MyTcpClient\MyTcpClient.suo
文件 24576 2009-03-01 19:24 tcp聊天程序\MyTcpServer\MyTcpServer\bin\Debug\MyTcpServer.exe
文件 24064 2009-03-01 19:24 tcp聊天程序\MyTcpServer\MyTcpServer\bin\Debug\MyTcpServer.pdb
文件 5632 2005-11-11 22:25 tcp聊天程序\MyTcpServer\MyTcpServer\bin\Debug\MyTcpServer.vshost.exe
文件 5013 2009-03-01 19:16 tcp聊天程序\MyTcpServer\MyTcpServer\Form1.cs
文件 6593 2009-03-01 18:29 tcp聊天程序\MyTcpServer\MyTcpServer\Form1.Designer.cs
文件 5814 2009-03-01 18:29 tcp聊天程序\MyTcpServer\MyTcpServer\Form1.resx
文件 474 2009-03-01 16:18 tcp聊天程序\MyTcpServer\MyTcpServer\MyTcpServer.cs
文件 3233 2009-03-01 16:36 tcp聊天程序\MyTcpServer\MyTcpServer\MyTcpServer.csproj
文件 558 2009-03-01 16:36 tcp聊天程序\MyTcpServer\MyTcpServer\MyTcpServer.csproj.user
............此处省略35个文件信息
相关资源
- C#实现简单QQ聊天程序
- C#简单窗体聊天程序
- C# Socket Tcp文件传输和文字聊天系统
- 用WPF开发的多人聊天室 语言C#
- C#编写UDP协议的一个局域网简单聊天工
- C#代码生成器(生成MVC三层代码)
- C#Oracle数据库备份
- C#代码生成工具
- UDP实现简单的聊天室
- SignalR在线聊天(websocket)
- Socket聊天室(客户端与服务端相互通
- C#网站项目使用SignalR技术实现实时聊
- 手机聊天程序(xamarin开发案例)
- asp.net 在线聊天室系统源代码.rar
- QQ高仿版 GG2014
- C# 使用 TcpClient,Socket 聊天
- C#版本气泡自定义控件,引用即可使用
- 104规约 C#实现代码
- .net C#代码生成器
- Unity和C#实现TCP网络聊天
- qq聊天程序--C#版
- ASP.NET聊天室277399
- C#开发的聊天小程序
- c#精品即时会议聊天完整版
- 成语接龙C#代码以前写的,暂时放这里
- SiriusCoder C#代码生成器
- winform五子棋联机版
- asp.net聊天室
- 狂人代码生成器V3.0 C#代码生成器 实体
- C#仿QQ聊天软件源码, 即时通信源码
评论
共有 条评论