Document

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();
        }
    }
}
posted @ 2017-08-03 16:58  从未被超越  阅读(3626)  评论(0编辑  收藏  举报