資源簡介
C#TCP聊天室C#TCP聊天室

代碼片段和文件信息
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?TCP聊天室客戶端
{
????public?partial?class?Form1?:?Form
????{
????????private?IPEndPoint?MyServer;
????????private?Socket?sock;
????????private?byte[]?buffer;
????????private?byte[]?send;
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????????sock?=?new?Socket(AddressFamily.InterNetwork?SocketType.Stream?ProtocolType.Tcp);
????????????buffer?=?new?byte[65535];
????????????send?=?new?byte[65535];
????????????CheckForIllegalCrossThreadCalls?=?false;
????????}
????????private?void?button2_Click(object?sender?EventArgs?e)
????????{
????????????if?(textBox5.Text?==?““)
????????????{
????????????????MessageBox.Show(“請輸入你的昵稱!“);
????????????????return;
????????????}
????????????MyServer?=?new?IPEndPoint(IPAddress.Parse(textBox3.Text)?Convert.ToInt32(textBox4.Text));
????????????textBox5.ReadOnly?=?true;
????????????try
????????????{
????????????????sock.Connect(MyServer);
????????????????MessageBox.Show(“服務器連接成功!“);
????????????????sock.Send(Encoding.Unicode.GetBytes(textBox5.Text+“進入了房間\r\n“));
????????????????sock.BeginReceive(buffer?0?buffer.Length?0?new?AsyncCallback(ReceiveCallback)?null);
????????????}
????????????catch
????????????{
????????????????MessageBox.Show(“服務器連接失敗!“);
????????????}
????????}
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????send?=?Encoding.Unicode.GetBytes(textBox5.Text?+?“說:\r\n“?+?textBox2.Text?+?“\r\n\r\n“);
????????????if?(sock.Connected)
????????????{
????????????????sock.Send(send);
????????????????textBox2.Text?=?““;
????????????}
????????????else
????????????{
????????????????MessageBox.Show(“請先登入服務器!“);
????????????}
????????}
????????private?void?ReceiveCallback(IAsyncResult?ar)
????????{
????????????try
????????????{
????????????????int?read?=?sock.EndReceive(ar);
????????????????textBox1.AppendText(?Encoding.Unicode.GetString(buffer?0?read));
????????????????sock.BeginReceive(buffer?0?buffer.Length?0?new?AsyncCallback(ReceiveCallback)?null);
????????????}
????????????catch
????????????{
????????????????MessageBox.Show(“服務器已關閉!“);
????????????}
????????}
????????private?void?Form1_FormClosing(object?sender?FormClosingEventArgs?e)
????????{
????????????if?(sock.Connected)
????????????{
????????????????sock.Send(Encoding.Unicode.GetBytes(textBox5.Text?+?“離開了房間\r\n“));
????????????????sock.Shutdown(SocketShutdown.Both);
????????????????sock.Disconnect(false);
????????????}
????????????sock.Close();
????????}
????????private?void?textBox1_TextChanged(object?sender?EventArgs?e)
????????{
????????????this.textBox1.ScrollToCare
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????24576??2007-06-07?12:55??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\bin\Debug\TCP聊天室客戶端.exe
?????文件??????28160??2007-06-07?12:55??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\bin\Debug\TCP聊天室客戶端.pdb
?????文件???????5632??2005-11-11?22:25??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\bin\Debug\TCP聊天室客戶端.vshost.exe
?????文件???????3393??2007-06-07?12:55??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\Form1.cs
?????文件???????9317??2007-06-07?12:49??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\Form1.Designer.cs
?????文件???????5814??2007-06-07?12:49??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\Form1.resx
?????文件????????842??2007-06-07?12:49??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\obj\Debug\TCP聊天室客戶端.csproj.GenerateResource.Cache
?????文件??????24576??2007-06-07?12:55??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\obj\Debug\TCP聊天室客戶端.exe
?????文件????????180??2007-06-07?12:49??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\obj\Debug\TCP聊天室客戶端.Form1.resources
?????文件??????28160??2007-06-07?12:55??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\obj\Debug\TCP聊天室客戶端.pdb
?????文件????????180??2007-04-13?15:25??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\obj\Debug\TCP聊天室客戶端.Properties.Resources.resources
?????文件????????366??2007-06-07?12:56??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\obj\TCP聊天室客戶端.csproj.FileList.txt
?????文件????????480??2007-04-13?14:27??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\Program.cs
?????文件???????1190??2007-04-13?14:27??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\Properties\AssemblyInfo.cs
?????文件???????2896??2007-04-13?14:27??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\Properties\Resources.Designer.cs
?????文件???????5612??2007-04-13?14:27??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\Properties\Resources.resx
?????文件???????1104??2007-04-13?14:27??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\Properties\Settings.Designer.cs
?????文件????????249??2007-04-13?14:27??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\Properties\Settings.settings
?????文件???????3249??2007-04-13?14:46??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端\TCP聊天室客戶端.csproj
?????文件????????952??2007-04-13?14:27??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端.sln
????..A..H.?????16896??2007-06-07?12:56??C#TCP聊天室\TCP聊天室客戶端\TCP聊天室客戶端.suo
?????文件??????20480??2007-06-07?12:44??C#TCP聊天室\TCP聊天室服務器\TCP聊天室\bin\Debug\TCP聊天室.exe
?????文件??????26112??2007-06-07?12:44??C#TCP聊天室\TCP聊天室服務器\TCP聊天室\bin\Debug\TCP聊天室.pdb
?????文件???????5632??2005-11-11?22:25??C#TCP聊天室\TCP聊天室服務器\TCP聊天室\bin\Debug\TCP聊天室.vshost.exe
?????文件??????20480??2007-04-13?10:26??C#TCP聊天室\TCP聊天室服務器\TCP聊天室\bin\Release\TCP聊天室.exe
?????文件??????22016??2007-04-13?10:26??C#TCP聊天室\TCP聊天室服務器\TCP聊天室\bin\Release\TCP聊天室.pdb
?????文件???????2451??2007-06-07?12:44??C#TCP聊天室\TCP聊天室服務器\TCP聊天室\Form1.cs
?????文件???????2467??2007-04-13?10:55??C#TCP聊天室\TCP聊天室服務器\TCP聊天室\Form1.Designer.cs
?????文件???????5814??2007-04-13?10:55??C#TCP聊天室\TCP聊天室服務器\TCP聊天室\Form1.resx
?????文件????????842??2007-04-13?16:13??C#TCP聊天室\TCP聊天室服務器\TCP聊天室\obj\Debug\TCP聊天室.csproj.GenerateResource.Cache
............此處省略43個文件信息
評論
共有 條評論