C# SuperSocket服務端入門(一)


1,新建一個控制台應用程序,.NET版本4.0

2,添加SuperSocket(1.6.1).Binaries\Net40\Debug  目錄下的:

SuperSocket的dll文件(

log4net.dll,

SuperSocket.Common.dll,

SuperSocket.SocketBase.dll,

SuperSocket.SocketEngine.dll)到此項目的引用

【你也可以使用日志框架,這里沒有使用】

3,添加系統的 
System.Configuration;

System.Configuration.Install;到引用中

4,在默認的Program.cs 代碼中 添加 命名空間 
using SuperSocket.Common;
using SuperSocket.SocketBase;
using SuperSocket.SocketEngine;

using SuperSocket.SocketBase.Config;

5,詳見代碼:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
using SuperSocket.Common;
using SuperSocket.SocketBase;
using SuperSocket.SocketEngine;
using SuperSocket.SocketBase.Config;
 
namespace WebSocketSeviceConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("service");
            //實例化服務器對象
            AppServer appServer = new AppServer();
            var serverConfig = new ServerConfig();
 
            //ip: 服務器監聽的ip地址。你可以設置具體的地址,也可以設置為下面的值 Any 
            //serverConfig.Ip = "184.56.41.24";
 
            serverConfig.Port = 8848;
            if (!appServer.Setup(serverConfig))
            { 
                Console.WriteLine("Failed to setup!");
                return;
            }
            if (!appServer.Start())
            {
                Console.WriteLine("Failed to start!");
                return;
            }
            Console.WriteLine("ssssss前置機啟動成功!,輸入q關閉服務器");
            while (Console.ReadKey().KeyChar != 'q')
            {
                continue;
            }
            appServer.Stop();
            Console.WriteLine("服務器已經關閉");
            Console.ReadKey();
        }
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM