• 大小: 11.15MB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2023-07-12
  • 语言: 其他
  • 标签: websocket  

资源简介

服务端是.net控制台程序,客户端是网页。本人从项目中快速抽离出来的,所以有很多没用的dll,还请谅解,关注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服务端
    /// 

    public static class WS_Server
    {
        /// 
        /// 端口
        /// 

        /// 
        /// 侦听线程
        /// 

        private static Thread _listenTh = null;
        /// 
        /// 侦听Socket
        /// 

        private static Socket _socket = null;
        /// 
        /// 客户端连接池
        /// 

        public static List ClientList = new List();
        /// 
        /// 启动侦听
        /// 

        /// 侦听的端口默认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启动成功正在侦听...“);
            }
            catch (Exception ex)
            {
                RdfLog.WriteException(ex “启动侦听异常“);
            }
        }
        /// 
        /// 停止侦听
        /// 

        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)
            {

            }
        }
        /// 
        /// 开始侦听
        /// 

        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();
                }
            }
    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        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个文件信息

评论

共有 条评论