自定义AppServer

TelnetSever.cs
public class TelnetServer : AppServer<TelnetSession>
{
protected override bool Setup(IRootConfig rootConfig, IServerConfig config)
{
return base.Setup(rootConfig, config);
} protected override void OnStarted()
{
base.OnStarted();
} protected override void OnStopped()
{
base.OnStopped();
}
}
TelnetSession.cs
public class TelnetSession:AppSession<TelnetSession,StringRequestInfo>
{
protected override void OnSessionStarted()
{
Console.WriteLine(this.SessionID + ":Client connected");
Send("Welcome to SuperSocket Telnet Server");
} protected override void HandleUnknownRequest(SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo)
{
Send("Unknow request");
} protected override void HandleException(Exception e)
{
this.Send("Application error: {0}", e.Message);
} protected override void OnSessionClosed(CloseReason reason)
{
//add you logics which will be executed after the session is closed
Console.WriteLine(this.SessionID + "Client Closed");
base.OnSessionClosed(reason);
}
}
Add.cs
public class Add : CommandBase<TelnetSession, StringRequestInfo>
{
public override void ExecuteCommand(TelnetSession session, StringRequestInfo requestInfo)
{
session.Send(requestInfo.Parameters.Select(p => Convert.ToInt32(p)).Sum().ToString());
}
}
Program.cs
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Press any key to start the server!"); Console.ReadKey();
Console.WriteLine();
var appServer = new TelnetServer(); var serverConfig = new ServerConfig
{
Port = //set the listening port
}; //Setup the appServer
if (!appServer.Setup(serverConfig))
{
Console.WriteLine("Failed to setup!");
Console.ReadKey();
return;
} Console.WriteLine(); //Try to start the appServer
if (!appServer.Start())
{
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
appServer.Stop();
}
}
自定义AppServer的更多相关文章
- SuperSocket入门(二)- 探索AppServer、AppSession,Conmmand和App.config
在上一篇文章中,我们已经了解到了如何在SuperSocket处理客户端请求. 同时我们可能会发现一个问题,如果我们的服务器端包含有很多复杂的业务逻辑,这样的switch/case代码将会很 ...
- c#Socket服务器与客户端的开发(2)
上一篇文章我们使用原生的socket分别实现了服务器和客户端, 本篇文章使用SuperSocket来开发实现服务器, 之前也介绍了SuperSocket是一个轻量级, 跨平台而且可扩展的 .Net/M ...
- SuperSocket 介绍
一.总体介绍 SuperSocket 是一个轻量级的可扩展的 Socket 开发框架,由江振宇先生开发. 官方网站:http://www.supersocket.net/ SuperSocket具有如 ...
- 关于 supersocket 不能通过Bootstrap 启动
App.config内容 <configSections> <section name="superSocket" type="SuperSocke ...
- SuperSocket 1.6.4 通过FixedHeaderReceiveFilter解析自定义协议
SuperSocket 提供了一些通用的协议解析工具, 你可以用他们简单而且快速的实现你自己的通信协议: TerminatorReceiveFilter (SuperSocket.SocketBase ...
- SuperSocket快速入门(三):实现你的AppServer和AppSession
什么是AppSession? AppSession 代表一个和客户端的逻辑连接,基于连接的操作应该定义于在该类之中.你可以用该类的实例发送数据到客户端,接收客户端发送的数据或者关闭连接.同时可以保存客 ...
- SuperSocket使用 IRequestInfo 和 IReceiveFilter 等对象实现自定义协议
为什么你要使用自定义协议? 通信协议用于将接收到的二进制数据转化成您的应用程序可以理解的请求. SuperSocket提供了一个内置的通信协议“命令行协议”定义每个请求都必须以回车换行"\r ...
- 通过视图实现自定义查询<持续完善中。。。>
目前实现: ----普通查询路径 /viewShow/viewShow/list.htm ----Echarts查询路劲 /viewShow/viewShow/echarts.htm 1.自定义查询条 ...
- supersockets和 AppSession,AppServer 配合工作
现在, 你已经有了 RequestInfo, ReceiveFilter 和 ReceiveFilterFactory, 但是你还没有正式使用它们. 如果你想让他们在你的程序里面可用, 你需要定义你们 ...
随机推荐
- 用最简单的例子理解策略模式(Strategy Pattern)
当一个动作有多种实现方法,在实际使用时,需要根据不同情况选择某个方法执行动作,就可以考虑使用策略模式. 把动作抽象成接口,比如把玩球抽象成接口. public interface IBall { vo ...
- symbol(s) not found for architecture armv7
Undefined symbols for architecture i386: “_OBJC_CLASS_$_XXX”, referenced from: objc-class-ref in XXX ...
- Android的基本常用的短信操作
1.调用系统发送短信界面(传入手机号码+短信内容) 2.隐藏发送短信(指定号码指定内容)(这里隐藏只是没有反写入数据库) 3.获得收件箱接收到的短信 4.Android屏蔽新短信通知提示信息:(Con ...
- Win8 下配置Java开发环境
背景: 大学期间学习过一段时间的JavaEE.不算很熟悉. 后来学习并在工作中很多其它是iOS开发,iOS的水平属于中上. 对技术已经有一定熟知程度. 近期为了写一些东西,须要用到Java写后台. 流 ...
- LeetCode: Implement strStr() [027]
[题目] Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if ...
- VC++ 改动VMware BIOS、uuid_location、ethernet0_address等
VC++ 改动VMware BIOS.uuid_location.ethernet0_address等.主要问题例如以下 (1)随机产生16进制数. (2)改动vmx相应项.依据规则一般仅仅改动最后三 ...
- Web系统自己主动化部署脚本
Web开发的项目,除了在本地直接执行外,还可能常常须要在server上部署. 写了个自己主动化部署的脚本,仅供參考. 不少地方须要配置路径.个人建议使用绝对路径,不用依赖执行脚本时所在的路径. #!/ ...
- JTS(Geometry)(转)
原文链接:http://blog.csdn.net/cdl2008sky/article/details/7268577 空间数据模型(1).JTS Geometry model (2).ISO Ge ...
- Android之AlarmManager
Android平台中,Alarm Manager Service控制着闹钟和唤醒功能.和其他系统服务一样,提供了一个辅助管理类-AlarmManager,我们只需要使用AlarmManager即可调用 ...
- GridControl 分组排序
方法一:纯代码 this.list.gridControl.ItemsSource = lsItem; this.list.gridControl.GroupBy("GroupTitle&q ...