Skip to content

Commit daa5939

Browse files
author
Juho Hovila
committed
Merge branch 'master' of https://github.com/invisibleroads/socketIO-client into merge-upstream
2 parents b01f74b + 1e58add commit daa5939

19 files changed

Lines changed: 162 additions & 287 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Node
2+
node_modules
13
# Python
24
*.egg*
35
*.py[co]

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ python:
33
- 2.6
44
- 2.7
55
- 3.4
6+
- 3.5
67
before_install:
78
- sudo apt-get install nodejs; node --version
89
install:

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
0.7
22
---
33
- Fixed thread cleanup
4+
- Fixed disconnect detection if defined directly thanks to Andreas Strikos
5+
- Fixed support for unicode payloads
46

57
0.6
68
---

README.rst

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ socketIO-client
66
===============
77
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.
88

9-
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.6 <https://pypi.python.org/pypi/socketIO-client/0.5.6>`_.
9+
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>`_.
1010

1111

1212
Installation
@@ -45,12 +45,13 @@ For debugging information, run these commands first. ::
4545

4646
import logging
4747
logging.getLogger('socketIO-client').setLevel(logging.DEBUG)
48+
logging.basicConfig()
4849

4950
Emit. ::
5051

5152
from socketIO_client import SocketIO, LoggingNamespace
5253

53-
with SocketIO('localhost', 8000, LoggingNamespace) as socketIO:
54+
with SocketIO('127.0.0.1', 8000, LoggingNamespace) as socketIO:
5455
socketIO.emit('aaa')
5556
socketIO.wait(seconds=1)
5657

@@ -61,18 +62,30 @@ Emit with callback. ::
6162
def on_bbb_response(*args):
6263
print('on_bbb_response', args)
6364

64-
with SocketIO('localhost', 8000, LoggingNamespace) as socketIO:
65+
with SocketIO('127.0.0.1', 8000, LoggingNamespace) as socketIO:
6566
socketIO.emit('bbb', {'xxx': 'yyy'}, on_bbb_response)
6667
socketIO.wait_for_callbacks(seconds=1)
6768

6869
Define events. ::
6970

7071
from socketIO_client import SocketIO, LoggingNamespace
7172

73+
def on_connect():
74+
print('connect')
75+
76+
def on_disconnect():
77+
print('disconnect')
78+
79+
def on_reconnect():
80+
print('reconnect')
81+
7282
def on_aaa_response(*args):
7383
print('on_aaa_response', args)
7484

75-
socketIO = SocketIO('localhost', 8000, LoggingNamespace)
85+
socketIO = SocketIO('127.0.0.1', 8000, LoggingNamespace)
86+
socketIO.on('connect', on_connect)
87+
socketIO.on('disconnect', on_disconnect)
88+
socketIO.on('reconnect', on_reconnect)
7689

7790
# Listen
7891
socketIO.on('aaa_response', on_aaa_response)
@@ -101,7 +114,7 @@ Define events in a namespace. ::
101114
print('on_aaa_response', args)
102115
self.emit('bbb')
103116

104-
socketIO = SocketIO('localhost', 8000, Namespace)
117+
socketIO = SocketIO('127.0.0.1', 8000, Namespace)
105118
socketIO.emit('aaa')
106119
socketIO.wait(seconds=1)
107120

@@ -114,7 +127,13 @@ Define standard events. ::
114127
def on_connect(self):
115128
print('[Connected]')
116129

117-
socketIO = SocketIO('localhost', 8000, Namespace)
130+
def on_reconnect(self):
131+
print('[Reconnected]')
132+
133+
def on_disconnect(self):
134+
print('[Disconnected]')
135+
136+
socketIO = SocketIO('127.0.0.1', 8000, Namespace)
118137
socketIO.wait(seconds=1)
119138

120139
Define different namespaces on a single socket. ::
@@ -131,7 +150,7 @@ Define different namespaces on a single socket. ::
131150
def on_aaa_response(self, *args):
132151
print('on_aaa_response', args)
133152

134-
socketIO = SocketIO('localhost', 8000)
153+
socketIO = SocketIO('127.0.0.1', 8000)
135154
chat_namespace = socketIO.define(ChatNamespace, '/chat')
136155
news_namespace = socketIO.define(NewsNamespace, '/news')
137156

@@ -144,11 +163,11 @@ Connect via SSL (https://github.com/invisibleroads/socketIO-client/issues/54). :
144163
from socketIO_client import SocketIO
145164

146165
# Skip server certificate verification
147-
SocketIO('https://localhost', verify=False)
166+
SocketIO('https://127.0.0.1', verify=False)
148167
# Verify the server certificate
149-
SocketIO('https://localhost', verify='server.crt')
168+
SocketIO('https://127.0.0.1', verify='server.crt')
150169
# Verify the server certificate and encrypt using client certificate
151-
socketIO = SocketIO('https://localhost', verify='server.crt', cert=(
170+
socketIO = SocketIO('https://127.0.0.1', verify='server.crt', cert=(
152171
'client.crt', 'client.key'))
153172

154173
Specify params, headers, cookies, proxies thanks to the `requests <http://python-requests.org>`_ library. ::
@@ -157,7 +176,7 @@ Specify params, headers, cookies, proxies thanks to the `requests <http://python
157176
from base64 import b64encode
158177

159178
SocketIO(
160-
localhost', 8000,
179+
'127.0.0.1', 8000,
161180
params={'q': 'qqq'},
162181
headers={'Authorization': 'Basic ' + b64encode('username:password')},
163182
cookies={'a': 'aaa'},
@@ -167,9 +186,20 @@ Wait forever. ::
167186

168187
from socketIO_client import SocketIO
169188

170-
socketIO = SocketIO('localhost', 8000)
189+
socketIO = SocketIO('127.0.0.1', 8000)
171190
socketIO.wait()
172191

192+
Don't wait forever. ::
193+
194+
from requests.exceptions import ConnectionError
195+
from socketIO_client import SocketIO
196+
197+
try:
198+
socket = SocketIO('127.0.0.1', 8000, wait_for_connection=False)
199+
socket.wait()
200+
except ConnectionError:
201+
print('The server is down. Try again later.')
202+
173203

174204
License
175205
-------
@@ -180,10 +210,10 @@ Credits
180210
-------
181211
- `Guillermo Rauch <https://github.com/rauchg>`_ wrote the `socket.io specification <https://github.com/automattic/socket.io-protocol>`_.
182212
- `Hiroki Ohtani <https://github.com/liris>`_ wrote `websocket-client <https://github.com/liris/websocket-client>`_.
183-
- `rod <http://stackoverflow.com/users/370115/rod>`_ wrote a `prototype for a Python client to a socket.io server <http://stackoverflow.com/questions/6692908/formatting-messages-to-send-to-socket-io-node-js-server-from-python-client>`_.
213+
- `Roderick Hodgson <https://github.com/roderickhodgson>`_ wrote a `prototype for a Python client to a socket.io server <http://stackoverflow.com/questions/6692908/formatting-messages-to-send-to-socket-io-node-js-server-from-python-client>`_.
184214
- `Alexandre Bourget <https://github.com/abourget>`_ wrote `gevent-socketio <https://github.com/abourget/gevent-socketio>`_, which is a socket.io server written in Python.
185215
- `Paul Kienzle <https://github.com/pkienzle>`_, `Zac Lee <https://github.com/zratic>`_, `Josh VanderLinden <https://github.com/codekoala>`_, `Ian Fitzpatrick <https://github.com/ifitzpatrick>`_, `Lucas Klein <https://github.com/lukasklein>`_, `Rui Chicoria <https://github.com/rchicoria>`_, `Travis Odom <https://github.com/burstaholic>`_, `Patrick Huber <https://github.com/stackmagic>`_, `Brad Campbell <https://github.com/bradjc>`_, `Daniel <https://github.com/dabidan>`_, `Sean Arietta <https://github.com/sarietta>`_, `Sacha Stafyniak <https://github.com/stafyniaksacha>`_ submitted code to expand support of the socket.io protocol.
186216
- `Bernard Pratz <https://github.com/guyzmo>`_, `Francis Bull <https://github.com/franbull>`_ wrote prototypes to support xhr-polling and jsonp-polling.
187217
- `Joe Palmer <https://github.com/softforge>`_ sponsored development.
188-
- `Eric Chen <https://github.com/taiyangc>`_, `Denis Zinevich <https://github.com/dzinevich>`_, `Thiago Hersan <https://github.com/thiagohersan>`_, `Nayef Copty <https://github.com/nayefc>`_, `Jörgen Karlsson <https://github.com/jorgen-k>`_, `Branden Ghena <https://github.com/brghena>`_, `Tim Landscheidt <https://github.com/scfc>`_, `Matt Porritt <https://github.com/mattporritt>`_, `Matt Dainty <https://github.com/bodgit>`_, `Thomaz de Oliveira dos Reis <https://github.com/thor27>`_, `Felix König <https://github.com/Felk>`_, `George Wilson <https://github.com/wilsonge>`_ suggested ways to make the connection more robust.
218+
- `Eric Chen <https://github.com/taiyangc>`_, `Denis Zinevich <https://github.com/dzinevich>`_, `Thiago Hersan <https://github.com/thiagohersan>`_, `Nayef Copty <https://github.com/nayefc>`_, `Jörgen Karlsson <https://github.com/jorgen-k>`_, `Branden Ghena <https://github.com/brghena>`_, `Tim Landscheidt <https://github.com/scfc>`_, `Matt Porritt <https://github.com/mattporritt>`_, `Matt Dainty <https://github.com/bodgit>`_, `Thomaz de Oliveira dos Reis <https://github.com/thor27>`_, `Felix König <https://github.com/Felk>`_, `George Wilson <https://github.com/wilsonge>`_, `Andreas Strikos <https://github.com/astrikos>`_, `Alessio Sergi <https://github.com/asergi>`_ `Claudio Yacarini <https://github.com/cyacarinic>`_, `Khairi Hafsham <https://github.com/khairihafsham>`_, `Robbie Clarken <https://github.com/RobbieClarken>`_ suggested ways to make the connection more robust.
189219
- `Merlijn van Deen <https://github.com/valhallasw>`_, `Frederic Sureau <https://github.com/fredericsureau>`_, `Marcus Cobden <https://github.com/leth>`_, `Drew Hutchison <https://github.com/drewhutchison>`_, `wuurrd <https://github.com/wuurrd>`_, `Adam Kecer <https://github.com/amfg>`_, `Alex Monk <https://github.com/Krenair>`_, `Vishal P R <https://github.com/vishalwy>`_, `John Vandenberg <https://github.com/jayvdb>`_, `Thomas Grainger <https://github.com/graingert>`_, `Daniel Quinn <https://github.com/danielquinn>`_, `Adric Worley <https://github.com/AdricEpic>`_, `Adam Roses Wight <https://github.com/adamwight>`_, `Jan Včelák <https://github.com/fcelda>`_ proposed changes that make the library more friendly and practical for you!

missions/PullRequests-20160331-1233.md

Lines changed: 0 additions & 140 deletions
This file was deleted.

missions/README.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

missions/TODO.goals

Lines changed: 0 additions & 37 deletions
This file was deleted.

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
])
1212
setup(
1313
name='socketIO-client',
14-
version='0.7.1-1',
14+
version='0.7.2',
1515
description='A socket.io client library',
1616
long_description=DESCRIPTION,
1717
license='MIT',
@@ -28,7 +28,7 @@
2828
install_requires=[
2929
'requests>=2.7.0',
3030
'six',
31-
'websocket-client==0.37.0'
31+
'websocket-client'
3232
],
3333
tests_require=[
3434
'nose',

0 commit comments

Comments
 (0)