資源簡(jiǎn)介
Socket,雙向通信,基礎(chǔ),控制臺(tái)
適合剛開始學(xué)Socket編程的同學(xué)

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Net.Sockets;
using?System.Net;
using?System.Threading;
namespace?socket客戶端
{
????class?Program
????{
????????static?Socket?socketLocal;?//避免多線程引入?yún)?shù)
????????static?void?Main(string[]?args)
????????{
????????????socketLocal?=?new?Socket(AddressFamily.InterNetwork?SocketType.Stream?ProtocolType.Tcp);
????????????IPEndPoint?iphost?=?new?IPEndPoint(IPAddress.Parse(“127.0.0.1“)?5678);
????????????try
????????????{
????????????????socketLocal.Connect(iphost);
????????????}
????????????catch?(Exception?e)
????????????{
????????????????Console.WriteLine(e);
????????????}
????????????Console.WriteLine(“成功連接到服務(wù)器!“);
????????????Thread?trdSend?=?new?Thread(new?ThreadStart(SendOut));
????????????trdSend.Start();
????????????Thread?trdRecv?=?new?Thread(new?ThreadStart(ReceiveWrite));
????????????trdRecv.Start();
????????????Console.ReadKey();
????????}
????????private?static?void?ReceiveWrite()
????????{
????????????byte[]?buffer?=?new?byte[1024];
????????????int?length;
????????????string?s?=?““;
????????????while?(true)
????????????{
????????????????length?=?socketLocal.Receive(buffer?buffer.Length?SocketFlags.None);
????????????????s?=?Encoding.Unicode.GetString(buffer);
????????????????Console.Write(s.TrimEnd(‘\0‘));
????????????}
????????}
????????private?static?void?SendOut()
????????{
????????????while?(true)
????????????{
????????????????string?str?=?Console.ReadLine();
????????????????socketLocal.Send(Encoding.Unicode.GetBytes(str));
????????????}
????????}
????}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????5632??2012-10-25?15:57??socket客戶端\bin\Debug\控制臺(tái)服務(wù)器.exe
?????文件??????13824??2012-10-25?15:57??socket客戶端\bin\Debug\控制臺(tái)服務(wù)器.pdb
?????文件??????11600??2012-10-25?15:58??socket客戶端\bin\Debug\控制臺(tái)服務(wù)器.vshost.exe
?????文件????????490??2010-03-17?22:39??socket客戶端\bin\Debug\控制臺(tái)服務(wù)器.vshost.exe.manifest
?????文件???????5857??2012-10-25?15:57??socket客戶端\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????565??2012-10-25?15:58??socket客戶端\obj\x86\Debug\socket客戶端.csproj.FileListAbsolute.txt
?????文件????????565??2012-10-25?15:01??socket客戶端\obj\x86\Debug\控制臺(tái)服務(wù)器.csproj.FileListAbsolute.txt
?????文件???????5632??2012-10-25?15:57??socket客戶端\obj\x86\Debug\控制臺(tái)服務(wù)器.exe
?????文件??????13824??2012-10-25?15:57??socket客戶端\obj\x86\Debug\控制臺(tái)服務(wù)器.pdb
?????文件???????1697??2012-10-25?15:57??socket客戶端\Program.cs
?????文件???????1374??2012-10-25?14:52??socket客戶端\Properties\AssemblyInfo.cs
?????文件???????2457??2012-10-25?14:55??socket客戶端\socket客戶端.csproj
?????文件???????6144??2012-10-25?15:57??socket服務(wù)器\bin\Debug\同步方法測(cè)試.exe
?????文件??????13824??2012-10-25?15:57??socket服務(wù)器\bin\Debug\同步方法測(cè)試.pdb
?????文件??????11600??2012-10-25?15:58??socket服務(wù)器\bin\Debug\同步方法測(cè)試.vshost.exe
?????文件????????490??2010-03-17?22:39??socket服務(wù)器\bin\Debug\同步方法測(cè)試.vshost.exe.manifest
?????文件???????5857??2012-10-25?15:57??socket服務(wù)器\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????5941??2012-10-25?15:32??socket服務(wù)器\obj\x86\Debug\ResolveAssemblyReference.cache
?????文件????????565??2012-10-25?15:58??socket服務(wù)器\obj\x86\Debug\socket服務(wù)器.csproj.FileListAbsolute.txt
?????文件????????565??2012-10-25?14:50??socket服務(wù)器\obj\x86\Debug\同步方法測(cè)試.csproj.FileListAbsolute.txt
?????文件???????6144??2012-10-25?15:57??socket服務(wù)器\obj\x86\Debug\同步方法測(cè)試.exe
?????文件??????13824??2012-10-25?15:57??socket服務(wù)器\obj\x86\Debug\同步方法測(cè)試.pdb
?????文件????????565??2012-10-25?15:02??socket服務(wù)器\obj\x86\Debug\控制臺(tái)客戶端.csproj.FileListAbsolute.txt
?????文件???????2397??2012-10-25?15:56??socket服務(wù)器\Program.cs
?????文件???????1374??2012-10-25?14:03??socket服務(wù)器\Properties\AssemblyInfo.cs
?????文件???????2454??2012-10-25?15:02??socket服務(wù)器\socket服務(wù)器.csproj
?????目錄??????????0??2012-10-25?15:58??socket客戶端\obj\x86\Debug\TempPE
?????目錄??????????0??2012-10-25?15:58??socket服務(wù)器\obj\x86\Debug\TempPE
?????目錄??????????0??2012-10-25?15:58??socket客戶端\obj\x86\Debug
?????目錄??????????0??2012-10-25?15:58??socket服務(wù)器\obj\x86\Debug
............此處省略15個(gè)文件信息
- 上一篇:超級(jí)瑪麗游戲C源碼 完整源程序
- 下一篇:程序員計(jì)算器
評(píng)論
共有 條評(píng)論