nodejs中socketcluster框架的客户端库
socketclusterclient的Python项目详细描述
#socketcluster client python
有关更多详细信息,请参阅示例:
overview
----
此客户端提供以下功能
-易于设置和使用
-可用于对所有服务器端功能进行广泛的单元测试
-支持发射和监听远程事件
-自动重新连接
-发布/订阅
-身份验证(jwt)
-支持python2.x.x/python3.x
安装使用
``python
sudo pip install socketclusterclient通过传递socketcluster服务器端点的url
``python
///创建一个socket实例
socket=socketcluster.socket("ws://localhost:8000/socketcluster/")
````
**重要提示**:socketcluster端点的默认url总是*ws://somedomainname.com/socketcluster/*。
\logging.basicconfig(format='%(levelname)s:%(message)s',level=logging.debug)
def on connect(socket):
logging.info("on connect got called")
def on disconnect(socket):
logging.info("on disconnect获取调用")
def onconnectorror(socket,error):
logging.info("on connect error got called")
def onsetauthentication(socket,令牌):
logging.info("token received"+token)
socket.setauthtoken(token)
def onauthentication(socket,is authenticated):
logging.info("authenticated is"+str(isauthenticated))
onDisconnect,onConnectorRor)
socket.setAuthenticationListener(onSetAuthentication,onauthentication)
socket.connect()
```
```
-默认情况下,与服务器的重新连接被禁用(从最新版本开始)。启用它并为连接配置延迟
``python
///这将设置自动重新连接到服务器的延迟为2秒,并无限重复它
socket.set delay(2)
socket.set reconnection(true)
socket.connect();
``
-默认情况下,在禁用(自最新版本以来)中记录消息,以启用它
``python
socket.enablelogger(true)
```
消息可以是string、boolean、int或json对象
``python
socket.emit("chat","hi")
``````
-发送带有确认信息的事件
``python
socket.emit ack("chat","hi",ack)
def ack(eventname,error,object):
打印"got ack data"+object+"and error"+error+,eventname为"+eventname
````
long或jsonobject。
`` python
+eventname
```
-将确认发送回服务器确认消息):
打印"got data"+object+"from eventname"+eventname
确认消息("这是错误","这是数据")
```
socket.subscribe('yell')
对象):
如果错误为"":
打印"已成功订阅频道"+频道
````
-获取已创建频道的列表:
```python
channels=socket.getsubscribedchannels()
````
频道上的事件
-对于发布事件:
`` python
puback)
def puback(channel,error,object):
如果错误是"":
打印"publish sent successfully to channel"+channel
`````
``python
``python
socket.onchannel('yell',channelmessage)
def channelmessage(key,object):
打印"got data"+object+"from key"+key
````
``python
socket.unsubscribe('yell')
对象):
如果错误为"":
打印"unsubscribed to channel"+channel
```
``python
socket=socketcluster.socket("wss://localhost:8000/socketcluster/")
socket.connect(sslopt={"cert_reqs":ssl.cert_none})
````
\http proxy
支持通过http proxy访问websocket。代理服务器必须允许"连接"方法到WebSocket端口。默认squid设置为"只允许连接https端口"。
``python
socket=socketcluster.socket("wss://localhost:8000/socketcluster/")
socket.connect(http_proxy_host="proxy_host_name",http_proxy_port=3128)
````
-通过内部记录器进行自定义设置,您可以获取logger实例并对其应用必要的设置。
``python
sclogger=socket.getlogger()
````
请按照下面的日志教程进行操作:https://docs.python.org/3/howto/logging-cookbook.html
有关更多详细信息,请参阅示例:
overview
----
此客户端提供以下功能
-易于设置和使用
-可用于对所有服务器端功能进行广泛的单元测试
-支持发射和监听远程事件
-自动重新连接
-发布/订阅
-身份验证(jwt)
-支持python2.x.x/python3.x
安装使用
``python
sudo pip install socketclusterclient通过传递socketcluster服务器端点的url
``python
///创建一个socket实例
socket=socketcluster.socket("ws://localhost:8000/socketcluster/")
````
**重要提示**:socketcluster端点的默认url总是*ws://somedomainname.com/socketcluster/*。
\logging.basicconfig(format='%(levelname)s:%(message)s',level=logging.debug)
def on connect(socket):
logging.info("on connect got called")
def on disconnect(socket):
logging.info("on disconnect获取调用")
def onconnectorror(socket,error):
logging.info("on connect error got called")
def onsetauthentication(socket,令牌):
logging.info("token received"+token)
socket.setauthtoken(token)
def onauthentication(socket,is authenticated):
logging.info("authenticated is"+str(isauthenticated))
onDisconnect,onConnectorRor)
socket.setAuthenticationListener(onSetAuthentication,onauthentication)
socket.connect()
```
```
-默认情况下,与服务器的重新连接被禁用(从最新版本开始)。启用它并为连接配置延迟
``python
///这将设置自动重新连接到服务器的延迟为2秒,并无限重复它
socket.set delay(2)
socket.set reconnection(true)
socket.connect();
``
-默认情况下,在禁用(自最新版本以来)中记录消息,以启用它
``python
socket.enablelogger(true)
```
消息可以是string、boolean、int或json对象
``python
socket.emit("chat","hi")
``````
-发送带有确认信息的事件
``python
socket.emit ack("chat","hi",ack)
def ack(eventname,error,object):
打印"got ack data"+object+"and error"+error+,eventname为"+eventname
````
long或jsonobject。
`` python
+eventname
```
-将确认发送回服务器确认消息):
打印"got data"+object+"from eventname"+eventname
确认消息("这是错误","这是数据")
```
socket.subscribe('yell')
对象):
如果错误为"":
打印"已成功订阅频道"+频道
````
-获取已创建频道的列表:
```python
channels=socket.getsubscribedchannels()
````
频道上的事件
-对于发布事件:
`` python
puback)
def puback(channel,error,object):
如果错误是"":
打印"publish sent successfully to channel"+channel
`````
``python
``python
socket.onchannel('yell',channelmessage)
def channelmessage(key,object):
打印"got data"+object+"from key"+key
````
socket.unsubscribe('yell')
对象):
如果错误为"":
打印"unsubscribed to channel"+channel
```
``python
socket=socketcluster.socket("wss://localhost:8000/socketcluster/")
socket.connect(sslopt={"cert_reqs":ssl.cert_none})
````
\http proxy
支持通过http proxy访问websocket。代理服务器必须允许"连接"方法到WebSocket端口。默认squid设置为"只允许连接https端口"。
``python
socket=socketcluster.socket("wss://localhost:8000/socketcluster/")
socket.connect(http_proxy_host="proxy_host_name",http_proxy_port=3128)
````
-通过内部记录器进行自定义设置,您可以获取logger实例并对其应用必要的设置。
``python
sclogger=socket.getlogger()
````
请按照下面的日志教程进行操作:https://docs.python.org/3/howto/logging-cookbook.html