資源簡介
很簡單的基于vs的聊天程序 適合初學者

代碼片段和文件信息
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?客戶端
{
????public?partial?class?Form1?:?Form
????{
???????
????????public?Form1()
????????{
????????????InitializeComponent();
????????????
????????}
????????private?Socket?socket;
????????private?Thread?thread;
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????????this.richTextBoxSend.Text?=?““;
????????????this.richTextBoxReceive.Text?=?““;
????????????this.listBoxState.Items.Clear();
????????}
????????private?void?buttonRequest_Click(object?sender?System.EventArgs?e)
????????{
????????????IPAddress?ip?=?IPAddress.Parse(this.textBoxIP.Text);
????????????IPEndPoint?server?=?new?IPEndPoint(ip?Int32.Parse(this.textBoxPort.Text));
????????????socket?=?new?Socket(AddressFamily.InterNetwork?SocketType.Stream?ProtocolType.Tcp);
????????????try
????????????{
????????????????socket.Connect(server);
????????????}
????????????catch
????????????{
????????????????MessageBox.Show(“與連接服務器失敗“);
????????????????return;
????????????}
????????????this.buttonRequest.Enabled?=?false;
????????????this.listBoxState.Items.Add(“與服務器連接成功“);
????????????thread?=?new?Thread(new?ThreadStart(AcceptMessage));
????????????thread.Start();
????????}
????????private?void?AcceptMessage()
????????{
????????????NetworkStream?netStream?=?new?NetworkStream(socket);
????????????while?(true)
????????????{
????????????????try
????????????????{
????????????????????byte[]?datasize?=?new?byte[4];
????????????????????netStream.Read(datasize?0?4);
????????????????????int?size?=?System.BitConverter.ToInt32(datasize?0);
????????????????????Byte[]?message?=?new?byte[size];
????????????????????int?dataleft?=?size;
????????????????????int?start?=?0;
????????????????????while?(dataleft>0)
????????????????????{
????????????????????????int?recv?=?netStream.Read(message?start?dataleft);
????????????????????????start?+=?recv;
????????????????????????dataleft?-=?recv;
????????????????????}
????????????????????this.richTextBoxReceive.Rtf?=?System.Text.Encoding.Unicode.GetString(message);
????????????????}
????????????????catch
????????????????{
????????????????????this.listBoxState.Items.Add(“服務器斷開連接“);
????????????????????break;
????????????????}
????????????}
????????}
????????private?void?buttonClose_Click(object?sender?System.EventArgs?e)
????????{
????????????try
????????????{
????????????????socket.Shutdown(SocketShutdown.Both);
????????????????socket.Close();
????????????????this.listBoxState.Items.Add(“與主機斷開連接“);
????????????????thread.Abort();
????????????}
????????????catch
????????????{
????????????????MessageBox.Show(“尚未與主機連接“);
????????????}
????????????this.buttonSend.Enabled?=?true;
????????}
???
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2011-05-09?22:53??簡單聊天程序\
?????目錄???????????0??2011-05-10?21:58??簡單聊天程序\客戶端1\
?????文件????????4283??2011-05-10?21:58??簡單聊天程序\客戶端1\客戶端.Txt
?????目錄???????????0??2011-04-27?18:04??簡單聊天程序\客戶端1\客戶端1\
?????文件?????????920??2011-04-24?00:11??簡單聊天程序\客戶端1\客戶端1.sln
?????文件???????18944??2011-05-18?17:47??簡單聊天程序\客戶端1\客戶端1.suo
?????目錄???????????0??2011-04-24?00:11??簡單聊天程序\客戶端1\客戶端1\bin\
?????目錄???????????0??2011-04-24?00:59??簡單聊天程序\客戶端1\客戶端1\bin\Debug\
?????文件???????12800??2011-04-27?18:04??簡單聊天程序\客戶端1\客戶端1\bin\Debug\客戶端1.exe
?????文件???????28160??2011-04-27?18:04??簡單聊天程序\客戶端1\客戶端1\bin\Debug\客戶端1.pdb
?????文件???????14328??2011-05-18?15:46??簡單聊天程序\客戶端1\客戶端1\bin\Debug\客戶端1.vshost.exe
?????文件?????????490??2007-07-21?00:33??簡單聊天程序\客戶端1\客戶端1\bin\Debug\客戶端1.vshost.exe.manifest
?????文件???????????1??2011-04-27?17:50??簡單聊天程序\客戶端1\客戶端1\ClassDiagram1.cd
?????文件????????4330??2011-04-27?18:04??簡單聊天程序\客戶端1\客戶端1\Form1.cs
?????文件????????9436??2011-04-27?16:47??簡單聊天程序\客戶端1\客戶端1\Form1.Designer.cs
?????文件????????5814??2011-04-27?16:47??簡單聊天程序\客戶端1\客戶端1\Form1.resx
?????目錄???????????0??2011-04-24?00:11??簡單聊天程序\客戶端1\客戶端1\obj\
?????目錄???????????0??2011-04-27?18:04??簡單聊天程序\客戶端1\客戶端1\obj\Debug\
?????目錄???????????0??2011-04-24?00:15??簡單聊天程序\客戶端1\客戶端1\obj\Debug\Refactor\
?????目錄???????????0??2011-04-24?00:11??簡單聊天程序\客戶端1\客戶端1\obj\Debug\TempPE\
?????文件?????????180??2011-04-27?18:04??簡單聊天程序\客戶端1\客戶端1\obj\Debug\客戶端.Form1.resources
?????文件?????????788??2011-05-18?15:46??簡單聊天程序\客戶端1\客戶端1\obj\Debug\客戶端1.csproj.FileListAbsolute.txt
?????文件?????????847??2011-04-27?16:47??簡單聊天程序\客戶端1\客戶端1\obj\Debug\客戶端1.csproj.GenerateResource.Cache
?????文件???????12800??2011-04-27?18:04??簡單聊天程序\客戶端1\客戶端1\obj\Debug\客戶端1.exe
?????文件???????28160??2011-04-27?18:04??簡單聊天程序\客戶端1\客戶端1\obj\Debug\客戶端1.pdb
?????文件?????????180??2011-04-27?18:04??簡單聊天程序\客戶端1\客戶端1\obj\Debug\客戶端1.Properties.Resources.resources
?????文件?????????488??2011-04-27?16:25??簡單聊天程序\客戶端1\客戶端1\Program.cs
?????目錄???????????0??2011-04-24?00:11??簡單聊天程序\客戶端1\客戶端1\Properties\
?????文件????????1366??2011-04-24?00:11??簡單聊天程序\客戶端1\客戶端1\Properties\AssemblyInfo.cs
?????文件????????2870??2011-04-24?00:11??簡單聊天程序\客戶端1\客戶端1\Properties\Resources.Designer.cs
?????文件????????5612??2011-04-24?00:11??簡單聊天程序\客戶端1\客戶端1\Properties\Resources.resx
............此處省略38個文件信息
- 上一篇:圖像壓縮與解壓縮算法解析
- 下一篇:wireshark抓包實驗之HTTP
評論
共有 條評論