socket.io客户端库

socketIO-client-nexus的Python项目详细描述


Socketio客户端

这是一个用于python的客户机库。您可以使用它为socket.io服务器编写测试代码。

这是实现socket.io 2.x更改的分叉版本。您可以在这里找到原始的

请注意,此版本实现了不向后兼容的socket.io protocol 1.x。如果要使用socket.io协议0.9(与gevent socketio兼容)进行通信,请使用socketio client 0.5.7.2

安装

在隔离的环境中安装软件包。

VIRTUAL_ENV=$HOME/.virtualenv

# Prepare isolated environment
virtualenv $VIRTUAL_ENV

# Activate isolated environment
source $VIRTUAL_ENV/bin/activate

# Install package
pip install -U socketIO-client

用法

激活隔离环境。

VIRTUAL_ENV=$HOME/.virtualenv
source $VIRTUAL_ENV/bin/activate

启动socket.io服务器。

cd $(python -c "import os, socketIO_client;\
    print(os.path.dirname(socketIO_client.__file__))")

DEBUG=* node tests/serve.js  # Start socket.io server in terminal one
DEBUG=* node tests/proxy.js  # Start proxy server in terminal two
nosetests                    # Run tests in terminal three

有关调试信息,请先运行这些命令。

import logging
logging.getLogger('socketIO-client').setLevel(logging.DEBUG)
logging.basicConfig()

发射,

from socketIO_client import SocketIO, LoggingNamespace

with SocketIO('localhost', 8000, LoggingNamespace) as socketIO:
    socketIO.emit('aaa')
    socketIO.wait(seconds=1)

通过回调发出。

from socketIO_client import SocketIO, LoggingNamespace

def on_bbb_response(*args):
    print('on_bbb_response', args)

with SocketIO('localhost', 8000, LoggingNamespace) as socketIO:
    socketIO.emit('bbb', {'xxx': 'yyy'}, on_bbb_response)
    socketIO.wait_for_callbacks(seconds=1)

定义事件。

from socketIO_client import SocketIO, LoggingNamespace

def on_connect():
    print('connect')

def on_disconnect():
    print('disconnect')

def on_reconnect():
    print('reconnect')

def on_aaa_response(*args):
    print('on_aaa_response', args)

socketIO = SocketIO('localhost', 8000, LoggingNamespace)
socketIO.on('connect', on_connect)
socketIO.on('disconnect', on_disconnect)
socketIO.on('reconnect', on_reconnect)

# Listen
socketIO.on('aaa_response', on_aaa_response)
socketIO.emit('aaa')
socketIO.emit('aaa')
socketIO.wait(seconds=1)

# Stop listening
socketIO.off('aaa_response')
socketIO.emit('aaa')
socketIO.wait(seconds=1)

# Listen only once
socketIO.once('aaa_response', on_aaa_response)
socketIO.emit('aaa')  # Activate aaa_response
socketIO.emit('aaa')  # Ignore
socketIO.wait(seconds=1)

在命名空间中定义事件。

from socketIO_client import SocketIO, BaseNamespace

class Namespace(BaseNamespace):

    def on_aaa_response(self, *args):
        print('on_aaa_response', args)
        self.emit('bbb')

socketIO = SocketIO('localhost', 8000, Namespace)
socketIO.emit('aaa')
socketIO.wait(seconds=1)

定义标准事件。

from socketIO_client import SocketIO, BaseNamespace

class Namespace(BaseNamespace):

    def on_connect(self):
        print('[Connected]')

    def on_reconnect(self):
        print('[Reconnected]')

    def on_disconnect(self):
        print('[Disconnected]')

socketIO = SocketIO('localhost', 8000, Namespace)
socketIO.wait(seconds=1)

在单个套接字上定义不同的命名空间。

VIRTUAL_ENV=$HOME/.virtualenv

# Prepare isolated environment
virtualenv $VIRTUAL_ENV

# Activate isolated environment
source $VIRTUAL_ENV/bin/activate

# Install package
pip install -U socketIO-client
0

通过SSL连接(https://github.com/invisibleroads/socketio-client/issues/54" rel="nofollow">https://github.com/invisibleroads/socketio-client/issues/54)。

VIRTUAL_ENV=$HOME/.virtualenv

# Prepare isolated environment
virtualenv $VIRTUAL_ENV

# Activate isolated environment
source $VIRTUAL_ENV/bin/activate

# Install package
pip install -U socketIO-client
1

通过 请求库指定参数、标题、cookies和代理。

VIRTUAL_ENV=$HOME/.virtualenv

# Prepare isolated environment
virtualenv $VIRTUAL_ENV

# Activate isolated environment
source $VIRTUAL_ENV/bin/activate

# Install package
pip install -U socketIO-client
2

永远等待。

VIRTUAL_ENV=$HOME/.virtualenv

# Prepare isolated environment
virtualenv $VIRTUAL_ENV

# Activate isolated environment
source $VIRTUAL_ENV/bin/activate

# Install package
pip install -U socketIO-client
3

不要永远等待。

VIRTUAL_ENV=$HOME/.virtualenv

# Prepare isolated environment
virtualenv $VIRTUAL_ENV

# Activate isolated environment
source $VIRTUAL_ENV/bin/activate

# Install package
pip install -U socketIO-client
4

许可证

此软件在麻省理工学院许可证下提供。

学分

0.7</H3>
  • 固定线程清理
  • 修复了由于Andreas Strikos直接定义的断开连接检测
  • 固定支持Unicode有效载荷

0.6</H3>
  • 由于Sean Arietta和Joe Palmer,已升级到Socket.io Protocol 1.x
  • 修复了对Python3的支持
  • 固定SSL支持
  • 添加锁以解决轮询传输的并发问题
  • 添加了socketio.off()和socketio.once()

0.5</H3>
  • 增加了对Python3的支持
  • 由于bernard pratz,增加了对jsonp轮询的支持
  • 由于francis bull,增加了对xhr轮询的支持
  • 添加了对查询参数和cookies的支持
  • 修复了由于travis odom而在自定义命名空间中发送确认的问题
  • 重写库以使用协程而不是线程来节省内存

0.4</H3>
  • 添加了对自定义头和代理的支持,这要归功于瑞和萨哈尔
  • 由于zac lee,增加了对服务器端回调的支持
  • 由于Alexandre Bourget,已将频道功能合并到BaseNamespace中

0.3</H3>
  • 增加了对安全连接的支持
  • 添加了socketio.wait()
  • 改进了rhythmicthread和listenerthread中的异常处理

0.2</H3>
  • 由于Paul Kienzle,增加了对回调和频道的支持
  • 采纳了Josh Vanderlinden和Ian Fitzpatrick的建议

0.1</H3>
  • 包装好的stackoverflow中的代码
  • 在连接失败时向析构函数添加异常处理

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

推荐PyPI第三方库


热门话题
java OpenShift的齿轮特性   java如何在Liferay站点的每个页面上放置公司地址和电话?   java确定整数数组中是否存在一个子集,在两个条件下求和到给定的目标值   序列化为什么java中的serialVersionUID必须是静态的、最终的、长类型的?   java响应返回null   java注入接口实现Quarkus   java我不明白为什么第二次排序的运行时间比第一次慢?   (Java)显示图像的最佳方式?   java Android应用程序因添加布局而崩溃   java如何在运行时获取泛型变量的类   java Selenium web驱动程序:无效的选择器:*:WebKitFullScreenSentor   Spring中的java注入值始终为空   Eclipse中带有TestNG插件的@BeforeSuite和@AfterSuite的java问题   使用trycatch块、filewriter和printwriter在java中创建自定义类   如何在Java 安卓上绘制相交的两条线