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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用ContentExchange设置请求属性   java Spark/Hdfs/Hdfsclient兼容性   java springcloudstreamkafka配置:instanceCount和instanceIndex   Java中web服务序列化日期   java用动态数据替换占位符   java git gc似乎覆盖了一个packfile,留下了一个打开的文件描述符,其中包含对“oldxxx.pack”的引用   为什么Apache项目对Java版本敏感?   java Anylogic帮助如何在导入的3dobject通过输送机上的多个“站”时更改其颜色?   JavaEclipseNeonM2E可以导入一个大型项目,但似乎不能自动解决依赖关系   java@FindBy搜索具有满足条件的子元素的元素   java如何将ActionEvent e与键绑定一起使用?   java转换以集中方式从外部库抛出的异常   java中用户文件/数据文件与系统/程序文件的区别   java使用变量字符串或字符作为对象名   字体使用Java图形操纵字符串中每个字符的形状   JavaFX图表移动数据   java RandomAccessFile:将所有项设置为相同的字节数?   java Google Play inapp Billing onPurchasesUpdated()错误响应代码1   java在不知道属性名和属性数的情况下处理json对象   java是否可以一次从HazelcastInstance(映射和列表)中删除所有数据?