没有合适的资源?快使用搜索试试~ 我知道了~
SuperSocket 1.5文档
4星 · 超过85%的资源 需积分: 10 31 下载量 23 浏览量
2013-04-02
15:40:52
上传
评论
收藏 1.4MB PDF 举报
温馨提示
试读
74页
为了方便在没有网络的情况下查看,整理了一下SuperSocket 1.5的文档
资源推荐
资源详情
资源评论
1
目录
1. A Telnet Example ......................................................................... 2
2. Implement your AppServer and AppSession ............................... 8
3. Start SuperSocket by Configuration ........................................... 12
4. SuperSocket Basic Configuration ............................................... 16
5. Built-in command line protocol ................................................. 21
6. Implement your own communication protocol with ................ 24
7. The Built-in Common Format Protocol Implementation Tools .. 29
8. Get the connected event and closed event of a connection ..... 33
9. Push data to clients from server initiative ................................. 35
10. Extend Server Configuration .................................................... 37
11. Command Filter ....................................................................... 40
12. Connection Filter ..................................................................... 43
13. Multiple Listeners .................................................................... 48
14. Multiple Server Instances ........................................................ 50
15. Implement Your Commands by Dynamic Language ................ 53
16. Logging in SuperSocket ............................................................ 57
17. The Built in Flash Silverlight Policy Server in SuperSocket ...... 61
18. Enable TLS/SSL trasnferring layer encryption in SuperSocket . 63
19. Run SuperSocket in Windows Azure ........................................ 65
20. Run SuperSocket in Linux/Unix ............................................... 70
21. Upgrade from SuperSocket 1.4 ................................................ 71
2
1. A Telnet Example
Create a Console project and add references of
SuperSocket
1.
Create a "Console Application" project. After the project is created, you should change the
target framework of this project from "Client Profile" to a full framework. Because this
application will run as server and the SuperSocket is not compiled with "Client Profile".
2.
Add SuperSocket's dll (SuperSocket.Common.dll, SuperSocket.SocketBase.dll,
SuperSocket.SocketEngine.dll) in this project's reference
3.
Add log4net.dll in this project's reference, because SuerSocket uses it as default logging
framework
4.
Include log4net.config which is provided by SuperSocket in the project folder "Config" and
set it's Build Action to be "Content" and Copy to Output Directory to be "Copy if newer",
because log4net require it
Write the Start/Stop Server Code
static void Main(string[] args)
{
Console.WriteLine("Press any key to start the server!");
3
Console.ReadKey();
Console.WriteLine();
var appServer = new AppServer();
//Setup the appServer
if (!appServer.Setup(2012)) //Setup with listening port
{
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("The server started successfully, press key 'q' to
stop it!");
while (Console.ReadKey().KeyChar != 'q')
{
Console.WriteLine();
continue;
}
//Stop the appServer
appServer.Stop();
Console.WriteLine("The server was stopped!");
Console.ReadKey();
}
4
Handle the Incomming Connection
1.
Register new session connected event handler
2.
appServer.NewSessionConnected += new
SessionHandler<AppSession>(appServer_NewSessionConnected);
3.
Send a welcome message to client in the handler
4.
static void appServer_NewSessionConnected(AppSession session)
5.
{
6.
session.Send("Welcome to SuperSocket Telnet Server");
7.
}
8.
Test by telnet client
1.
open a telnet client
2.
type "telnet localhost 2012" ending with an "ENTER"
3.
you will get the message "Welcome to SuperSocket Telnet Server"
Process Requests
1.
Register request handler
2.
appServer.NewRequestReceived += new RequestHandler<AppSession,
StringRequestInfo>(appServer_NewRequestReceived);
3.
Implement request handler
4.
static void appServer_NewRequestReceived(AppSession session,
StringRequestInfo requestInfo)
5.
{
6.
switch (requestInfo.Key.ToUpper())
7.
{
8.
case("ECHO"):
9.
session.Send(requestInfo.Body);
10. break;
11.
12. case ("ADD"):
5
13. session.Send(requestInfo.Parameters.Select(p =>
Convert.ToInt32(p)).Sum().ToString());
14. break;
15.
16. case ("MULT"):
17.
18. var result = 1;
19.
20. foreach (var factor in
requestInfo.Parameters.Select(p => Convert.ToInt32(p)))
21. {
22. result *= factor;
23. }
24.
25. session.Send(result.ToString());
26. break;
27. }
28.}
requestInfo.Key is the request command line's first segment delimited by space,
requestInfo.Parameters is the left segments delimited by space
29.
Test by telnet client
You can open a telnet client to verify the above code.
After you connect the server, you can interact with server in this way (the message after
"C:" stands for client's request, the message after "S:" stands for server's response):
C: ECHO ABCDEF
S: ABCDEF
C: ADD 1 2
S: 3
C: ADD 250 250
S: 500
C: MULT 2 8
S: 16
C: MULT 125 2
S: 250
剩余73页未读,继续阅读
资源评论
- 祥云fly2014-04-02英文的 磕磕巴巴算是看完了 谢谢分享
- Yvan_Hou2013-10-14英文的,不过总比没有强,谢谢!
- lvdengmei2014-10-29英文的很蛋疼,比没有的强吧
- hpf6lsy2014-11-05是英文的,看不懂……
- chengangsb2014-08-30英文看不太懂,不过感谢整理
l19900099
- 粉丝: 0
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- DSP开发实战教程-国产DSP替代进口TI DSP的使用技巧 进芯DSP替换文件
- 植被恢复能力估算python代码(KNDVI代码).zip
- 基于java打造的深度学习框架,帮助你快速搭建神经网络,实现模型推理与训练,引擎支持自动求导,多线程与GPU运算
- 界线与不动产测绘智能计算经纬度及标注软件
- CANOPEN使用方法与教程
- 极影毁片圆 · 电脑字体设置.zip
- 同态加密部分算法实现Homomorphic-Encryption-main.zip
- helib同态加密socket通信helibsocket-master.zip
- pll_inst.vhd
- 快速入门同态加密homomorphic-encryption-master.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功