A TCP Services Frame
Project description
Network Core
一个能够用简洁的方式来构建通信服务的轻量级框架。
方法
此项目已上传 acdpnet · PyPI ,快速安装可使用以下命令。
pip install acdpnet -i https://pypi.org/simple
构建服务
基本框架
from acdpnet import services
app = services.Tree()
# extension
app.run(('0.0.0.0', 1035), token='ASDF')
通过以上代码可以快速构建一个服务端,但仍然无法投入使用,在此之上还需要加上用户认证的功能。
用户认证
简单的用户创建方式
app.idf.acessuid = {
'Name':'Password'
}
自定义用户认证
class Login(services.Idenfaction):
def setup(self):
pass
def Idenfy(self, account:str, key:str):
if key == self.acessuid.get(account):
return True
else:
return False
app.idf = Login()
在继承 services.Idenfaction 后,认证的方式请写在 Idenfy 方法中。之后覆盖 app.idf 。
服务拓展
完成了基本的框架后,就可以为服务端添加功能啦。
通过函数拓展
from acdpnet.tools import Conet
# 引用此类是为了在写代码时出现代码提示,可不引用
@app.command('command_name')
def Dosomething(conet:Conet):
pass
通过类拓展
from acdpnet.tools import Conet
class Serv:
def command_name_1(conet:Conet):
pass
def command_name_2(conet:Conet):
pass
app.extension(Serv)
在通过此方法拓展时,请勿在方法中添加 self ,同时方法的名称便是指令的名称。
通过内置拓展添加
此库中内置了一些预先写好的拓展,可以通过以下方式添加。
from acdpnet.extension import transfer
app.extension(transfer.Transfer)
构建客户端
基本方式
from acdpnet import nodes
app = nodes.BasicNode('Name', 'Password')
app.connect(('localhost', 1035), token='ASDF')
# do something
app.close()
发送与接收
发送命令及数据
data = {
...
}
app.send('Your command', data)
接收命令与数据
resp = app.recv()
# 由服务端决定返回 dict 或 list
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
acdpnet-2.2.1.tar.gz
(15.4 kB
view details)
Built Distribution
acdpnet-2.2.1-py3-none-any.whl
(17.1 kB
view details)
File details
Details for the file acdpnet-2.2.1.tar.gz
.
File metadata
- Download URL: acdpnet-2.2.1.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc6085c92705872667f5818442ff446505a4037d03ba504c41fadc92423edb0a |
|
MD5 | fdbcae60f32e6f5b9f5c6e971ba2ef59 |
|
BLAKE2b-256 | df2f2bc8b9d7bcb18c9cbbf0cd6dc341dcff545120e72b100a4ca120cf91cd0e |
File details
Details for the file acdpnet-2.2.1-py3-none-any.whl
.
File metadata
- Download URL: acdpnet-2.2.1-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 080d52a9dabc404460596208c72b6fb78521a725fc7280c75a768fabfa746c5b |
|
MD5 | 55fcd6568d22837767934c7dd13e4300 |
|
BLAKE2b-256 | 69b5769b11efedfc68541ad3122dfd5bbd8b7bf41f22133d98eab029e74c24f2 |