110,538
社区成员
发帖
与我相关
我的任务
分享
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.Protocol;
using SuperSocket.SocketBase.Command;
using SuperSocket.SocketBase.Config;
namespace TelnetServer
{
class Program
{
static void Main(string[] args)
{
#region 使用Bootstrap来通过配置启动SuperSocket
Console.WriteLine("Press any key to start the server!");
Console.ReadKey();
Console.WriteLine();
var bootstrap = BootstrapFactory.CreateBootstrap();
if (!bootstrap.Initialize())
{
Console.WriteLine("Failed to initialize!");
Console.ReadKey();
return;
}
var result = bootstrap.Start();
Console.WriteLine("Start result: {0}!", result);
if (result == StartResult.Failed)
{
Console.WriteLine("Failed to start!");
Console.ReadKey();
return;
}
Console.WriteLine("Press key 'q' to stop it!");
while (Console.ReadKey().KeyChar != 'q')
{
Console.WriteLine();
continue;
}
Console.WriteLine();
//Stop the appServer
bootstrap.Stop();
Console.WriteLine("The server was stopped!");
Console.ReadKey();
#endregion
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="superSocket"
type="SuperSocket.SocketEngine.Configuration.SocketServiceConfig, SuperSocket.SocketEngine" />
</configSections>
<appSettings>
<add key="ServiceName" value="SupperSocketService" />
</appSettings>
<superSocket>
<servers>
<server name="TelnetServers"
serverTypeName="TelnetServer"
ip="Any"
port="2020">
</server>
</servers>
<serverTypes>
<add name="TelnetServer"
type="SuperSocket.QuickStart.TelnetServer_StartByConfig.TelnetServer, SuperSocket.QuickStart.TelnetServer_StartByConfig"/>
</serverTypes>
</superSocket>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
<servers>
<server name="TelentServer"
textEncoding="UTF-8"
serverTypeName="MyServerType"
ip="Any"
port="8080">
</server>
</servers>
<serverTypes>
<add name="MyServerType"
type="supersocket_config.TelnetSever,supersocket_config"/>
</serverTypes>
</superSocket>
supersocket_config是我的命名空间,TelnetServer是服务的名称。