資源簡介
這是一個由c#窗體開發的簡單的聊天室系統,可以實現基本上聊天的所有功能,代碼完全清晰,歡迎下載學習!

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Text;
using?System.Net.Sockets;
using?System.Net;
using?System.IO;
namespace?MyConsoleChat
{
????class?Program
????{
????????private?Socket?soc;
????????private?Socket?clientSoc;
????????static?void?Main(string[]?args)
????????{
????????????Program?example;
????????????bool?isServer?=?false;
????????????System.Console.Out.WriteLine(“Is?the?endpoint?the?server?\nY/N“);
????????????char?c?=?(char)System.Console.Read();
????????????if?(c?==?‘y‘?||?c?==?‘Y‘)
????????????????isServer?=?true;
????????????example?=?new?Program(isServer);
????????????if?(isServer)
????????????????example.ServerSide();
????????????else
????????????????example.ClientSide();
????????}
????????public?Program(bool?isServer)
????????{
????????????IPEndPoint?ep;
????????????IPAddress?ip?=?Dns.GetHostByName(“localhost“).AddressList[0];
????????????if?(isServer)
????????????????ep?=?new?IPEndPoint(ip?999);
????????????else
????????????????ep?=?new?IPEndPoint(ip?998);
????????????soc?=?new?Socket(AddressFamily.InterNetwork?SocketType.Stream?ProtocolType.Tcp);
????????????soc.Bind(ep);
????????}
????????//服務器端
????????public?void?ServerSide()
{
int?count;
soc.Listen(1);
System.Console.WriteLine(“Begin?Listening...“);
clientSoc=soc.Accept();
System.Console.WriteLine(“Got?a?client“);
System.Console.ReadLine();
string?input=“Hello“;
byte[]?buf=new?byte[1024];
while(input!=“\\q“)
{
clientSoc.Send(Encoding.Default.GetBytes(input));
count=clientSoc.Receive(buf);
System.Console.WriteLine(Encoding.Default.GetString(buf0count));
input=System.Console.ReadLine();
}
clientSoc.Close();
soc.Close();
}
????????//客戶端
public?void?ClientSide()
{
int?count;
IPEndPoint?ep;
byte[]?buf=new?byte[1024];
IPAddress?ip=Dns.GetHostByName(“localhost“).AddressList[0];
ep=new?IPEndPoint(ip999);
soc.Connect(ep);
if(soc.Connected)
System.Console.WriteLine(“Successfully?Connected?to?the?Server“);
string?input=“Hello“;
System.Console.ReadLine();
while(input!=“\\q“)
{
count=soc.Receive(buf);
System.Console.WriteLine(Encoding.Default.GetString(buf0count));
input=System.Console.ReadLine();
soc.Send(Encoding.Default.GetBytes(input));
}
soc.Close();
}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????16384??2008-12-18?15:04??第13章\MyConsoleChat\MyConsoleChat\bin\Debug\MyConsoleChat.exe
?????文件??????15872??2008-12-18?15:04??第13章\MyConsoleChat\MyConsoleChat\bin\Debug\MyConsoleChat.pdb
?????文件???????5632??2005-11-11?22:25??第13章\MyConsoleChat\MyConsoleChat\bin\Debug\MyConsoleChat.vshost.exe
?????文件???????1960??2007-10-20?12:58??第13章\MyConsoleChat\MyConsoleChat\MyConsoleChat.csproj
?????文件??????16384??2008-12-18?15:04??第13章\MyConsoleChat\MyConsoleChat\obj\Debug\MyConsoleChat.exe
?????文件??????15872??2008-12-18?15:04??第13章\MyConsoleChat\MyConsoleChat\obj\Debug\MyConsoleChat.pdb
?????文件????????158??2007-10-20?13:38??第13章\MyConsoleChat\MyConsoleChat\obj\MyConsoleChat.csproj.FileList.txt
?????文件????????728??2008-12-18?15:04??第13章\MyConsoleChat\MyConsoleChat\obj\MyConsoleChat.csproj.FileListAbsolute.txt
?????文件???????2423??2007-10-20?13:09??第13章\MyConsoleChat\MyConsoleChat\Program.cs
?????文件???????1173??2007-10-20?12:58??第13章\MyConsoleChat\MyConsoleChat\Properties\AssemblyInfo.cs
?????文件????????928??2007-10-20?12:58??第13章\MyConsoleChat\MyConsoleChat.sln
????..A..H.?????10240??2008-12-18?15:05??第13章\MyConsoleChat\MyConsoleChat.suo
?????文件??????24576??2008-12-18?15:05??第13章\QQClient\QQClient\bin\Debug\QQClient.exe
?????文件??????26112??2008-12-18?15:05??第13章\QQClient\QQClient\bin\Debug\QQClient.pdb
?????文件???????5632??2005-11-11?22:25??第13章\QQClient\QQClient\bin\Debug\QQClient.vshost.exe
?????文件??????10326??2008-09-04?17:37??第13章\QQClient\QQClient\Form1.cs
?????文件??????11321??2008-06-16?17:31??第13章\QQClient\QQClient\Form1.Designer.cs
?????文件???????5814??2008-06-16?17:31??第13章\QQClient\QQClient\Form1.resx
?????文件????????842??2008-12-18?15:05??第13章\QQClient\QQClient\obj\Debug\QQClient.csproj.GenerateResource.Cache
?????文件??????24576??2008-12-18?15:05??第13章\QQClient\QQClient\obj\Debug\QQClient.exe
?????文件????????180??2008-12-18?15:05??第13章\QQClient\QQClient\obj\Debug\QQClient.Form1.resources
?????文件??????26112??2008-12-18?15:05??第13章\QQClient\QQClient\obj\Debug\QQClient.pdb
?????文件????????180??2008-12-18?15:05??第13章\QQClient\QQClient\obj\Debug\QQClient.Properties.Resources.resources
?????文件????????275??2009-09-27?19:30??第13章\QQClient\QQClient\obj\QQClient.csproj.FileList.txt
?????文件???????1734??2008-12-19?14:09??第13章\QQClient\QQClient\obj\QQClient.csproj.FileListAbsolute.txt
?????文件????????467??2008-06-12?19:12??第13章\QQClient\QQClient\Program.cs
?????文件???????1170??2008-06-12?19:12??第13章\QQClient\QQClient\Properties\AssemblyInfo.cs
?????文件???????2872??2008-06-12?19:12??第13章\QQClient\QQClient\Properties\Resources.Designer.cs
?????文件???????5612??2008-06-12?19:12??第13章\QQClient\QQClient\Properties\Resources.resx
?????文件???????1093??2008-06-12?19:12??第13章\QQClient\QQClient\Properties\Settings.Designer.cs
............此處省略51個文件信息
- 上一篇:ASP.NET數據庫中圖片存儲及讀取
- 下一篇:多元函數遺傳算法
評論
共有 條評論