資源簡(jiǎn)介
服務(wù)端是.net控制臺(tái)程序,客戶(hù)端是網(wǎng)頁(yè)。本人從項(xiàng)目中快速抽離出來(lái)的,所以有很多沒(méi)用的dll,還請(qǐng)諒解,關(guān)注websocket核心代碼就好了。
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Net;
using?System.Text;
using?Tools;
using?System.Linq;
using?System.Threading;
using?System.Net.Sockets;
using?System.Security.Cryptography;
namespace?ConsoleClient
{
????class?Program
????{
????????static?void?Main(string[]?args)
????????{
????????????WS_Server.Start();
????????????Console.ReadLine();
????????}
????}
????///?
????///?websocket服務(wù)端
????///?
????public?static?class?WS_Server
????{
????????///?
????????///?端口
????????///?
????????///?
????????///?偵聽(tīng)線(xiàn)程
????????///?
????????private?static?Thread?_listenTh?=?null;
????????///?
????????///?偵聽(tīng)Socket
????????///?
????????private?static?Socket?_socket?=?null;
????????///?
????????///?客戶(hù)端連接池
????????///?
????????public?static?List?ClientList?=?new?List();
????????///?
????????///?啟動(dòng)偵聽(tīng)
????????///?
????????///?偵聽(tīng)的端口默認(rèn)9000
????????public?static?void?Start(int?prot?=?9000)
????????{
????????????try
????????????{
????????????????if?(_listenTh?!=?null?&&?_socket?!=?null)
????????????????????return;
????????????????IPEndPoint?point?=?new?IPEndPoint(IPAddress.Parse(“127.0.0.1“)?prot);
????????????????_socket?=?new?Socket(AddressFamily.InterNetwork?SocketType.Stream?ProtocolType.Tcp);
????????????????_socket.Bind(point);
????????????????_socket.Listen(100);
????????????????_listenTh?=?new?Thread(new?ThreadStart(Listener));
????????????????_listenTh.Start();
????????????????RdfLog.WriteLog(“WS啟動(dòng)成功正在偵聽(tīng)...“);
????????????}
????????????catch?(Exception?ex)
????????????{
????????????????RdfLog.WriteException(ex?“啟動(dòng)偵聽(tīng)異?!埃?
????????????}
????????}
????????///?
????????///?停止偵聽(tīng)
????????///?
????????public?static?void?Stop()
????????{
????????????try
????????????{
????????????????if?(_socket?!=?null)
????????????????{
????????????????????_socket.Close();
????????????????????_socket.Dispose();
????????????????????_socket?=?null;
????????????????}
????????????????if?(_listenTh?!=?null)
????????????????{
????????????????????_listenTh.Abort();
????????????????????_listenTh?=?null;
????????????????}
????????????????ClientList.Clear();
????????????}
????????????catch?(Exception?ex)
????????????{
????????????}
????????}
????????///?
????????///?開(kāi)始偵聽(tīng)
????????///?
????????private?static?void?Listener()
????????{
????????????if?(_socket?==?null)
????????????????return;
????????????try
????????????{
????????????????while?(true)
????????????????{
????????????????????Socket?client?=?_socket.Accept();
????????????????????WS_Client?info?=?new?WS_Client?{?WSID?=?Guid.NewGuid()?Addresss?=?client.RemoteEndPoint.ToString()?Client?=?client?};
????????????????????ClientList.Add(info);
????????????????????info.Handshake();
????????????????}
????????????}
????
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件????????178??2016-12-08?09:41??websocket\ConsoleClient\App.config
?????文件????7781888??2016-09-28?17:39??websocket\ConsoleClient\bin\Debug\Aspose.Cells.dll
?????文件???31345152??2016-11-04?14:32??websocket\ConsoleClient\bin\Debug\Aspose.Slides.dll
?????文件????8743424??2016-09-28?17:39??websocket\ConsoleClient\bin\Debug\Aspose.Words.dll
?????文件??????36352??2016-12-08?09:40??websocket\ConsoleClient\bin\Debug\BaiDuMap.dll
?????文件?????128512??2016-12-08?09:40??websocket\ConsoleClient\bin\Debug\BaiDuMap.pdb
?????文件??????11264??2016-12-08?09:40??websocket\ConsoleClient\bin\Debug\ConsoleClient.exe
?????文件????????296??2016-09-29?10:35??websocket\ConsoleClient\bin\Debug\ConsoleClient.exe.config
?????文件??????24064??2016-12-08?09:40??websocket\ConsoleClient\bin\Debug\ConsoleClient.pdb
?????文件??????22696??2016-12-07?17:04??websocket\ConsoleClient\bin\Debug\ConsoleClient.vshost.exe
?????文件????????296??2016-09-29?10:35??websocket\ConsoleClient\bin\Debug\ConsoleClient.vshost.exe.config
?????文件????????490??2015-06-04?12:48??websocket\ConsoleClient\bin\Debug\ConsoleClient.vshost.exe.manifest
?????文件?????208896??2010-05-25?12:55??websocket\ConsoleClient\bin\Debug\ICSharpCode.SharpZipLib.dll
?????文件??????42496??2016-12-08?09:40??websocket\ConsoleClient\bin\Debug\Model.dll
?????文件?????103936??2016-12-08?09:40??websocket\ConsoleClient\bin\Debug\Model.pdb
?????文件??????48128??2016-09-28?17:37??websocket\ConsoleClient\bin\Debug\System.Linq.Dynamic.dll
?????文件??????45056??2016-12-08?09:40??websocket\ConsoleClient\bin\Debug\Tools.dll
?????文件?????101888??2016-12-08?09:40??websocket\ConsoleClient\bin\Debug\Tools.pdb
?????文件?????454656??2016-12-08?09:40??websocket\ConsoleClient\bin\Debug\WcfService.dll
?????文件?????863744??2016-12-08?09:40??websocket\ConsoleClient\bin\Debug\WcfService.pdb
?????文件??????23040??2016-12-08?09:40??websocket\ConsoleClient\bin\Debug\WeChat.dll
?????文件??????75264??2016-12-08?09:40??websocket\ConsoleClient\bin\Debug\WeChat.pdb
?????文件???????4031??2016-11-10?10:24??websocket\ConsoleClient\ConsoleClient.csproj
?????文件????????228??2016-11-07?09:23??websocket\ConsoleClient\ConsoleClient.csproj.user
?????文件????????257??2016-09-28?17:37??websocket\ConsoleClient\ConsoleClient.csproj.vspscc
?????文件???????2113??2016-12-08?09:40??websocket\ConsoleClient\obj\Debug\ConsoleClient.csproj.FileListAbsolute.txt
?????文件??????53192??2016-12-08?09:40??websocket\ConsoleClient\obj\Debug\ConsoleClient.csprojResolveAssemblyReference.cache
?????文件??????11264??2016-12-08?09:40??websocket\ConsoleClient\obj\Debug\ConsoleClient.exe
?????文件??????24064??2016-12-08?09:40??websocket\ConsoleClient\obj\Debug\ConsoleClient.pdb
?????文件??????39979??2016-11-07?09:42??websocket\ConsoleClient\obj\Debug\DesignTimeResolveAssemblyReferences.cache
............此處省略57個(gè)文件信息
評(píng)論
共有 條評(píng)論