• 大小: 1.36M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2020-12-26
  • 语言: C#
  • 标签: Socket  windows  

资源简介

  1)新建WinService服务,导入WebSocket编程所需要的应用,该项目引用不在.net驱动包中,需要自己手动加载,我将其放在根目录下Lib文件下。

  2)还是修改Program.cs,制定服务入口MyWebSocketService,在MyWebSocketService中实现服务所做的事情。

  3)实例一个SuperWebSocket对象server;

  4)新用户连接时创建会话连接(多连接);

    4.1)拿着连接直接发送。

  5)关闭会话时-----客户端关闭,发送到考场;考场关闭发送到客户端

  6)接收信息

    6.1)接收信息,发送出去

    6.2)如果没有连接则构建连接。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.ServiceProcess;
using SuperWebSocket;

namespace SuperWebSocketWindowsServiceDemo
{
    public partial class MyWebSocketService : Servicebase
    {
        public MyWebSocketService()
        {
            InitializeComponent();
        }

        WebSocketServer server;
        protected override void onstart(string[] args)
        {
            var ip = ConfigurationManager.AppSettings[“APWebSocketIP“];
            var port = ConfigurationManager.AppSettings[“APWebSocketPort“];
            //WebSocket服务器端启动
            server = new WebSocketServer();
            if (!server.Setup(int.Parse(port)))
            {
                //Debug.Write(“WebSocke

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-08-28 17:10  SuperWebSocketWindowsServiceDemo\
     目录           0  2017-08-28 17:11  SuperWebSocketWindowsServiceDemo\Lib\
     文件      294912  2014-10-31 16:24  SuperWebSocketWindowsServiceDemo\Lib\log4net.dll
     文件      491008  2014-10-09 11:38  SuperWebSocketWindowsServiceDemo\Lib\Newtonsoft.Json.dll
     文件       29696  2014-10-09 14:33  SuperWebSocketWindowsServiceDemo\Lib\SuperSocket.Common.dll
     文件       15872  2014-10-09 14:33  SuperWebSocketWindowsServiceDemo\Lib\SuperSocket.Facility.dll
     文件       94720  2014-10-09 14:33  SuperWebSocketWindowsServiceDemo\Lib\SuperSocket.Socketbase.dll
     文件       70144  2014-10-09 14:33  SuperWebSocketWindowsServiceDemo\Lib\SuperSocket.SocketEngine.dll
     文件       66048  2014-10-09 14:33  SuperWebSocketWindowsServiceDemo\Lib\SuperWebSocket.dll
     目录           0  2017-08-29 10:04  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\
     文件        1561  2017-08-28 17:37  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo.sln
     文件       71680  2017-08-29 09:14  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo.v12.suo
     文件         415  2017-08-29 08:33  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\App.config
     目录           0  2017-08-28 16:53  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\bin\
     目录           0  2017-08-28 20:17  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\bin\Debug\
     文件      294912  2014-10-31 16:24  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\bin\Debug\log4net.dll
     文件      491008  2014-10-09 11:38  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\bin\Debug\Newtonsoft.Json.dll
     文件       29696  2014-10-09 14:33  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\bin\Debug\SuperSocket.Common.dll
     文件       15872  2014-10-09 14:33  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\bin\Debug\SuperSocket.Facility.dll
     文件       94720  2014-10-09 14:33  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\bin\Debug\SuperSocket.Socketbase.dll
     文件       70144  2014-10-09 14:33  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\bin\Debug\SuperSocket.SocketEngine.dll
     文件       66048  2014-10-09 14:33  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\bin\Debug\SuperWebSocket.dll
     文件       10240  2017-08-28 17:37  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\bin\Debug\SuperWebSocketWindowsServiceDemo.exe
     文件         415  2017-08-29 08:33  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\bin\Debug\SuperWebSocketWindowsServiceDemo.exe.config
     文件        1258  2017-08-28 17:39  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\bin\Debug\SuperWebSocketWindowsServiceDemo.InstallLog
     文件        7467  2017-08-28 17:39  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\bin\Debug\SuperWebSocketWindowsServiceDemo.InstallState
     文件       24224  2017-08-29 10:02  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\bin\Debug\SuperWebSocketWindowsServiceDemo.vshost.exe
     文件         415  2017-08-29 08:33  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\bin\Debug\SuperWebSocketWindowsServiceDemo.vshost.exe.config
     文件         490  2017-03-19 05:00  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\bin\Debug\SuperWebSocketWindowsServiceDemo.vshost.exe.manifest
     目录           0  2017-08-28 16:53  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\bin\Release\
     文件        2546  2017-08-28 16:54  SuperWebSocketWindowsServiceDemo\SuperWebSocketWindowsServiceDemo\log4net.config
............此处省略60个文件信息

评论

共有 条评论