supersocket实现你的命令

现在, 如果你有一个命令行协议的服务器实例 "IronPythonServer", 而且我们要用 Python 创建一个 "ADD" 命令用于让两个整数相加,然后把计算结果返回给客户端, 我们就要完成下面的步骤:

1.创建 python 脚本文件 "ADD.py", 并书写如下内容:

def execute(session, request):

    session.Send(str(int(request[0]) + int(request[1])))

2.将此文件放入工作目录的子目录 "Command" 里

3.WorkRoot -> Command -> ADD.py

4.启动服务器,并通过Telnet客户端验证功能

telnet 127.0.0.1 2012

Client: ADD 100 150

Server: 250

你会发现 ADD.py 位于 Command 文件夹的根目录, 因此 SuperSocket 允许所有实例加载它. 如果你只想要服务器实例 "IronPythonServer" 使用它, 你应该把脚本文件放到Command目录的子目录 "IronPythonServer" 里面:

WorkRoot -> Command -> IronPythonServer -> ADD.py

原文地址:https://www.cnblogs.com/fanweisheng/p/11127007.html