Skip to content

Commit

Permalink
Adjusted readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Nakroma committed Oct 13, 2017
1 parent 4907501 commit dbab81f
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
.. image:: https://travis-ci.org/invisibleroads/socketIO-client.svg?branch=master
:target: https://travis-ci.org/invisibleroads/socketIO-client


socketIO-client
socketIO-client-nexus
===============
Here is a `socket.io <http://socket.io>`_ client library for Python. You can use it to write test code for your socket.io server.

This is a forked version to implement the Socket.io 2.x changes. You can find the original `here <https://github.com/invisibleroads/socketIO-client>`_.

Please note that this version implements `socket.io protocol 1.x <https://github.com/automattic/socket.io-protocol>`_, which is not backwards compatible. If you want to communicate using `socket.io protocol 0.9 <https://github.com/learnboost/socket.io-spec>`_ (which is compatible with `gevent-socketio <https://github.com/abourget/gevent-socketio>`_), please use `socketIO-client 0.5.7.2 <https://pypi.python.org/pypi/socketIO-client/0.5.7.2>`_.


Installation
------------
Expand All @@ -24,7 +18,7 @@ Install the package in an isolated environment. ::
source $VIRTUAL_ENV/bin/activate

# Install package
pip install -U socketIO-client
pip install -U socketIO-client-nexus


Usage
Expand All @@ -36,8 +30,8 @@ Activate isolated environment. ::

Launch your socket.io server. ::

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

DEBUG=* node tests/serve.js # Start socket.io server in terminal one
DEBUG=* node tests/proxy.js # Start proxy server in terminal two
Expand All @@ -46,20 +40,20 @@ Launch your socket.io server. ::
For debugging information, run these commands first. ::

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

Emit. ::

from socketIO_client import SocketIO, LoggingNamespace
from socketIO_client_nexus import SocketIO, LoggingNamespace

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

Emit with callback. ::

from socketIO_client import SocketIO, LoggingNamespace
from socketIO_client_nexus import SocketIO, LoggingNamespace

def on_bbb_response(*args):
print('on_bbb_response', args)
Expand All @@ -70,7 +64,7 @@ Emit with callback. ::

Define events. ::

from socketIO_client import SocketIO, LoggingNamespace
from socketIO_client_nexus import SocketIO, LoggingNamespace

def on_connect():
print('connect')
Expand Down Expand Up @@ -108,7 +102,7 @@ Define events. ::

Define events in a namespace. ::

from socketIO_client import SocketIO, BaseNamespace
from socketIO_client_nexus import SocketIO, BaseNamespace

class Namespace(BaseNamespace):

Expand All @@ -122,7 +116,7 @@ Define events in a namespace. ::

Define standard events. ::

from socketIO_client import SocketIO, BaseNamespace
from socketIO_client_nexus import SocketIO, BaseNamespace

class Namespace(BaseNamespace):

Expand All @@ -140,7 +134,7 @@ Define standard events. ::

Define different namespaces on a single socket. ::

from socketIO_client import SocketIO, BaseNamespace
from socketIO_client_nexus import SocketIO, BaseNamespace

class ChatNamespace(BaseNamespace):

Expand All @@ -162,7 +156,7 @@ Define different namespaces on a single socket. ::

Connect via SSL (https://github.com/invisibleroads/socketIO-client/issues/54). ::

from socketIO_client import SocketIO
from socketIO_client_nexus import SocketIO

# Skip server certificate verification
SocketIO('https://localhost', verify=False)
Expand All @@ -174,7 +168,7 @@ Connect via SSL (https://github.com/invisibleroads/socketIO-client/issues/54). :

Specify params, headers, cookies, proxies thanks to the `requests <http://python-requests.org>`_ library. ::

from socketIO_client import SocketIO
from socketIO_client_nexus import SocketIO
from base64 import b64encode

SocketIO(
Expand All @@ -186,15 +180,15 @@ Specify params, headers, cookies, proxies thanks to the `requests <http://python

Wait forever. ::

from socketIO_client import SocketIO
from socketIO_client_nexus import SocketIO

socketIO = SocketIO('localhost', 8000)
socketIO.wait()

Don't wait forever. ::

from requests.exceptions import ConnectionError
from socketIO_client import SocketIO
from socketIO_client_nexus import SocketIO

try:
socket = SocketIO('localhost', 8000, wait_for_connection=False)
Expand Down

0 comments on commit dbab81f

Please sign in to comment.