step1.先加入库SuperSocket.Common.dll, SuperSocket.SocketBase.dll, SuperSocket.SocketEngine.dll,log4net.dll,System.Threading.dll。同时还需引入NET中的System.Configuration。如果要使用默认日志框架,需要复制Config文件夹

step2.代码实现

     class Program
{
static void Main(string[] args)
{
Console.WriteLine("press any key to start the server");
Console.ReadKey();
Console.WriteLine();
AppServer server = new AppServer();
if (!server.Setup())
{
Console.WriteLine("Failed to setup");
Console.ReadKey();
return;
} server.NewSessionConnected += new SessionHandler<AppSession>(server_NewSessionConnected);
server.NewRequestReceived += new RequestHandler<AppSession, SuperSocket.SocketBase.Protocol.StringRequestInfo>(server_NewRequestReceived); if (!server.Start())
{
Console.WriteLine("Failed to start");
Console.ReadKey();
return;
} Console.WriteLine("The server started successfully, press key 'q' to stop it!"); while (Console.ReadKey().KeyChar != 'q')
{
Console.WriteLine();
continue;
}
Console.WriteLine();
server.Stop();
Console.WriteLine("The server was stopped!");
} static void server_NewRequestReceived(AppSession session, SuperSocket.SocketBase.Protocol.StringRequestInfo requestInfo)
{
Console.WriteLine(requestInfo.Key + " " + requestInfo.Body);
switch (requestInfo.Key.ToUpper())
{
case ("ECHO"):
string r = requestInfo.Body;
session.Send(r);
Console.WriteLine(r);
break; case ("ADD"):
string r2= requestInfo.Parameters.Select(p => Convert.ToInt32(p)).Sum().ToString();
session.Send(r2);
Console.WriteLine(r2);
break; case ("MULT"): var result = ; foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p)))
{
result *= factor;
} session.Send(result.ToString());
Console.WriteLine(result);
break;
}
} static void server_NewSessionConnected(AppSession session)
{
Console.WriteLine(session.SessionID + ":connect successed");
}
}

Step3.测试:代码测试:在window中运行里面输入telnet 127.0.0.1 8000  然后按回车就可以了

最新文章

  1. poj[1187][Noi 01]陨石的秘密
  2. docker-image container 基本操作 -常用命令
  3. oracle 10g在redhat5下的安装
  4. WPF:实现主应用程序单一实例运行方式总结
  5. wikioi 3116 高精度练习之加法
  6. 截获控制台程序关闭事件(SetConsoleCtrlHandler)
  7. Blend4精选案例图解教程(一):丰富的形状(Shape)资源
  8. 2017-2-17 c#基础学习 (控制台程序的创建,输出,输入,定义变量,变量赋值,值覆盖,值拼接,值打印)
  9. Erlang调度器细节探析
  10. GIS大数据存储预研
  11. css3 @media支持ie8用respond.js 解决IE6~8的响应式布局问题
  12. Centos7上vsftp脚本--&gt; sh vsftp.sh 用户名 密码 --&gt; sh vsftp.sh install
  13. 调用WebService的简单方法
  14. 推广App篇
  15. Windows 下安装 swoole 具体步骤(php)
  16. LeetCode 905 Sort Array By Parity 解题报告
  17. Ext.net combobox 的disabled
  18. 配置Oracle E-Business Suite Integrated SOA Gateway Release 12.1.2/12.1.3
  19. js正则表达式实现手机号码,密码正则验证
  20. testlogin

热门文章

  1. no scheme 问题
  2. selenium+python自动化82-只截某个元素的图
  3. iOS中alloc与init
  4. OpenCV学习(27) 直方图(4)
  5. YUI+Ant 实现JS CSS压缩
  6. GDB调试工具总结
  7. 微信小程序开发:设置消息推送
  8. Office EXCEL 不用VB,你也可以制作自己的Excel菜单!
  9. JSP基本的语法、3个编译指令、7个动作指令、9个内置对象
  10. struts2学习笔记(3)---Action中訪问ServletAPI获取真实类型的Servlet元素