C# SuperSocket服务端入门(一)
生活随笔
收集整理的這篇文章主要介紹了
C# SuperSocket服务端入门(一)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1,新建一個(gè)控制臺應(yīng)用程序,.NET版本4.0
2,添加SuperSocket(1.6.1).Binaries\Net40\Debug??目錄下的:
SuperSocket的dll文件(
log4net.dll,
SuperSocket.Common.dll,
SuperSocket.SocketBase.dll,
SuperSocket.SocketEngine.dll)到此項(xiàng)目的引用
【你也可以使用日志框架,這里沒有使用】
3,添加系統(tǒng)的?
System.Configuration;
System.Configuration.Install;到引用中
4,在默認(rèn)的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");
??????????? //實(shí)例化服務(wù)器對象
??????????? AppServer appServer = new AppServer();
??????????? var serverConfig = new ServerConfig(); //ip: 服務(wù)器監(jiān)聽的ip地址。你可以設(shè)置具體的地址,也可以設(shè)置為下面的值 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前置機(jī)啟動成功!,輸入q關(guān)閉服務(wù)器");
??????????? while (Console.ReadKey().KeyChar != 'q')
??????????? {
??????????????? continue;
??????????? }
??????????? appServer.Stop();
??????????? Console.WriteLine("服務(wù)器已經(jīng)關(guān)閉");
??????????? Console.ReadKey();
??????? }
??? }
}
總結(jié)
以上是生活随笔為你收集整理的C# SuperSocket服务端入门(一)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python Linux系统信息
- 下一篇: OpenStack第十四个版本及14项重