SAMPClient#
- class astropy.samp.SAMPClient(hub, name=None, description=None, metadata=None, addr=None, port=0, callable=True)[源代码]#
基类:
object实用程序类,它提供了创建和管理与SAMP兼容的XML-RPC服务器(充当SAMP可调用客户机应用程序)的工具。
- 参数:
- hub :
SAMPHubProxySAMPHubProxy 的实例
SAMPHubProxy用于与SAMP Hub进行消息传递。- name :
str,可选Python:字符串,可选 客户名称(对应于
samp.name元数据关键字)。- description :
str,可选Python:字符串,可选 客户描述(对应于
samp.description.text元数据关键字)。- metadata :
dict,可选Python:Dict,可选 标准SAMP格式的客户端应用程序元数据。
- addr :
str,可选Python:字符串,可选 监听地址(或IP)。如果无法访问internet,则默认为127.0.0.1,否则默认为主机名。
- port :
int,可选PYTHON:int,可选 正在侦听XML-RPC服务器套接字端口。如果left设置为0(默认值),操作系统将选择一个空闲端口。
- callable : bool ,可选可选的布尔
客户端是否可以接收呼叫和通知。如果设置为
False,则客户端可以发送通知和呼叫,但不能接收任何通知和呼叫。
- hub :
属性摘要
客户端当前是否已注册。
客户端当前是否正在运行。
方法总结
bind_receive_call(mtype, function[, ...])将特定的MType调用绑定到函数或类方法。
bind_receive_message(mtype, function[, ...])将特定的MType绑定到函数或类方法,用于调用或通知。
bind_receive_notification(mtype, function[, ...])将特定的MType通知绑定到函数或类方法。
bind_receive_response(msg_tag, function)将特定的msg标记响应绑定到函数或类方法。
declare_metadata([metadata])声明支持的客户端应用程序元数据。
declare_subscriptions([subscriptions])声明客户端希望订阅的MType,用MType绑定方法隐式定义
bind_receive_notification()和bind_receive_call().get_private_key\()返回用于在注册时获得的标准配置文件通信的客户端私钥 (
samp.private-key)get_public_id\()返回注册时获得的公共客户端ID (
samp.self-id)receive_call(private_key, sender_id, msg_id, ...)标准可调用客户端
receive_call方法。receive_notification(private_key, sender_id, ...)标准可调用客户端
receive_notification方法。receive_response(private_key, responder_id, ...)标准可调用客户端
receive_response方法。register\()将客户机注册到SAMP Hub。
start\()在单独的线程中启动客户端(非阻塞)。
stop([timeout])停止客户端。
unbind_receive_call(mtype[, declare])从调用绑定表中删除指定的MType并从中取消订阅客户端(如果需要)。
unbind_receive_notification(mtype[, declare])从通知绑定表中删除指定的MType,并从中取消订阅客户端(如果需要)。
unbind_receive_response(msg_tag)从响应绑定表中删除指定的消息标记。
unregister\()从SAMP Hub注销客户端。
属性文档
- is_registered#
客户端当前是否已注册。
- is_running#
客户端当前是否正在运行。
方法文件
- bind_receive_call(mtype, function, declare=True, metadata=None)[源代码]#
将特定的MType调用绑定到函数或类方法。
函数的格式必须为:
def my_function_or_method(<self,> private_key, sender_id, msg_id, mtype, params, extra)
在哪里?
private_key是客户端私钥,sender_id是通知发件人ID,msg_id是集线器消息id,mtype是消息MType,params是否设置了消息参数(的内容"samp.params")extra是包含任何额外消息映射项的字典。默认情况下,客户机自动声明为订阅MType。- 参数:
- mtype :
strPython :字符串 要捕获的MType。
- function :
callable()Python:Callable() 在以下情况下要使用的应用程序函数
mtype收到。- declare : bool ,可选可选的布尔
指定是否必须将客户端自动声明为已订阅MType(另请参阅
declare_subscriptions())- metadata :
dict,可选Python:Dict,可选 包含要声明与订阅的MType关联的附加元数据的字典(另请参阅
declare_subscriptions())
- mtype :
- bind_receive_message(mtype, function, declare=True, metadata=None)[源代码]#
将特定的MType绑定到函数或类方法,用于调用或通知。
函数的格式必须为:
def my_function_or_method(<self,> private_key, sender_id, msg_id, mtype, params, extra)
在哪里?
private_key是客户端私钥,sender_id是通知发件人ID,msg_id是集线器消息id(仅调用,否则为None)mtype是消息MType,params是否设置了消息参数(的内容"samp.params")extra是包含任何额外消息映射项的字典。默认情况下,客户机自动声明为订阅MType。- 参数:
- mtype :
strPython :字符串 要捕获的MType。
- function :
callable()Python:Callable() 在以下情况下要使用的应用程序函数
mtype收到。- declare : bool ,可选可选的布尔
指定是否必须将客户端自动声明为已订阅MType(另请参阅
declare_subscriptions())- metadata :
dict,可选Python:Dict,可选 包含要声明与订阅的MType关联的附加元数据的字典(另请参阅
declare_subscriptions())
- mtype :
- bind_receive_notification(mtype, function, declare=True, metadata=None)[源代码]#
将特定的MType通知绑定到函数或类方法。
函数的格式必须为:
def my_function_or_method(<self,> private_key, sender_id, mtype, params, extra)
在哪里?
private_key是客户端私钥,sender_id是通知发件人ID,mtype是消息MType,params是否设置了通知消息参数(的内容"samp.params")extra是包含任何额外消息映射项的字典。默认情况下,客户机自动声明为订阅MType。- 参数:
- mtype :
strPython :字符串 要捕获的MType。
- function :
callable()Python:Callable() 在以下情况下要使用的应用程序函数
mtype收到。- declare : bool ,可选可选的布尔
指定是否必须将客户端自动声明为已订阅MType(另请参阅
declare_subscriptions())- metadata :
dict,可选Python:Dict,可选 包含要声明与订阅的MType关联的附加元数据的字典(另请参阅
declare_subscriptions())
- mtype :
- bind_receive_response(msg_tag, function)[源代码]#
将特定的msg标记响应绑定到函数或类方法。
函数的格式必须为:
def my_function_or_method(<self,> private_key, responder_id, msg_tag, response)
在哪里?
private_key是客户端私钥,responder_id是消息响应程序ID,msg_tag是否在呼叫时提供消息标签,以及response是收到的响应。- 参数:
- msg_tag :
strPython :字符串 要捕获的消息标记。
- function :
callable()Python:Callable() 在以下情况下要使用的应用程序函数
msg_tag收到。
- msg_tag :
- declare_metadata(metadata=None)[源代码]#
声明支持的客户端应用程序元数据。
- 参数:
- metadata :
dict,可选Python:Dict,可选 包含SAMP定义文档中定义的客户端应用程序元数据的字典。如果省略,则不声明元数据。
- metadata :
- declare_subscriptions(subscriptions=None)[源代码]#
声明客户端希望订阅的MType,用MType绑定方法隐式定义
bind_receive_notification()和bind_receive_call().可选的
subscriptions映射可以添加到传递给declare_subscriptions()方法。- 参数:
- subscriptions :
dict,可选Python:Dict,可选 包含要订阅的mtype列表的字典,其格式与
subscriptions地图传递给declare_subscriptions()方法。
- subscriptions :
- get_private_key()[源代码]#
返回用于在注册时获得的标准配置文件通信的客户端私钥 (
samp.private-key)- 返回:
- key :
strPython :字符串 私钥客户端。
- key :
- receive_call(private_key, sender_id, msg_id, message)[源代码]#
标准可调用客户端
receive_call方法。当
bind_receive_call()方法用于将不同的操作绑定到多个类型。如果自定义的可调用客户端实现继承自SAMPClient类应重写此方法。备注
重写时,此方法必须始终返回字符串结果(甚至为空)。
- receive_notification(private_key, sender_id, message)[源代码]#
标准可调用客户端
receive_notification方法。当
bind_receive_notification()方法用于将不同的操作绑定到多个类型。如果自定义的可调用客户端实现继承自SAMPClient类应重写此方法。备注
重写时,此方法必须始终返回字符串结果(甚至为空)。
- receive_response(private_key, responder_id, msg_tag, response)[源代码]#
标准可调用客户端
receive_response方法。当
bind_receive_response()方法用于将不同的操作绑定到多个类型。如果自定义的可调用客户端实现继承自SAMPClient类应重写此方法。备注
重写时,此方法必须始终返回字符串结果(甚至为空)。
- unbind_receive_call(mtype, declare=True)[源代码]#
从调用绑定表中删除指定的MType并从中取消订阅客户端(如果需要)。
- 参数:
- mtype :
strPython :字符串 要删除的MType。
- declare : bool布尔
指定是否必须将客户端自动声明为从MType取消订阅(另请参见
declare_subscriptions())
- mtype :
- unbind_receive_notification(mtype, declare=True)[源代码]#
从通知绑定表中删除指定的MType,并从中取消订阅客户端(如果需要)。
- 参数:
- mtype :
strPython :字符串 要删除的MType。
- declare : bool布尔
指定是否必须将客户端自动声明为从MType取消订阅(另请参见
declare_subscriptions())
- mtype :