Skip to content

Commit

Permalink
Replace localhost with explicit 127.0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
invisibleroads authored and francoijs committed Mar 24, 2019
1 parent d149d84 commit 1117aad
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
24 changes: 12 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Emit. ::

from socketIO_client_nexus import SocketIO, LoggingNamespace

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

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

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

Expand All @@ -78,7 +78,7 @@ Define events. ::
def on_aaa_response(*args):
print('on_aaa_response', args)

socketIO = SocketIO('localhost', 8000, LoggingNamespace)
socketIO = SocketIO('127.0.0.1', 8000, LoggingNamespace)
socketIO.on('connect', on_connect)
socketIO.on('disconnect', on_disconnect)
socketIO.on('reconnect', on_reconnect)
Expand Down Expand Up @@ -110,7 +110,7 @@ Define events in a namespace. ::
print('on_aaa_response', args)
self.emit('bbb')

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

Expand All @@ -129,7 +129,7 @@ Define standard events. ::
def on_disconnect(self):
print('[Disconnected]')

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

Define different namespaces on a single socket. ::
Expand All @@ -146,7 +146,7 @@ Define different namespaces on a single socket. ::
def on_aaa_response(self, *args):
print('on_aaa_response', args)

socketIO = SocketIO('localhost', 8000)
socketIO = SocketIO('127.0.0.1', 8000)
chat_namespace = socketIO.define(ChatNamespace, '/chat')
news_namespace = socketIO.define(NewsNamespace, '/news')

Expand All @@ -159,11 +159,11 @@ Connect via SSL (https://github.com/invisibleroads/socketIO-client/issues/54). :
from socketIO_client_nexus import SocketIO

# Skip server certificate verification
SocketIO('https://localhost', verify=False)
SocketIO('https://127.0.0.1', verify=False)
# Verify the server certificate
SocketIO('https://localhost', verify='server.crt')
SocketIO('https://127.0.0.1', verify='server.crt')
# Verify the server certificate and encrypt using client certificate
socketIO = SocketIO('https://localhost', verify='server.crt', cert=(
socketIO = SocketIO('https://127.0.0.1', verify='server.crt', cert=(
'client.crt', 'client.key'))

Specify params, headers, cookies, proxies thanks to the `requests <http://python-requests.org>`_ library. ::
Expand All @@ -172,7 +172,7 @@ Specify params, headers, cookies, proxies thanks to the `requests <http://python
from base64 import b64encode

SocketIO(
'localhost', 8000,
'127.0.0.1', 8000,
params={'q': 'qqq'},
headers={'Authorization': 'Basic ' + b64encode('username:password')},
cookies={'a': 'aaa'},
Expand All @@ -182,7 +182,7 @@ Wait forever. ::

from socketIO_client_nexus import SocketIO

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

Don't wait forever. ::
Expand All @@ -191,7 +191,7 @@ Don't wait forever. ::
from socketIO_client_nexus import SocketIO

try:
socket = SocketIO('localhost', 8000, wait_for_connection=False)
socket = SocketIO('127.0.0.1', 8000, wait_for_connection=False)
socket.wait()
except ConnectionError:
print('The server is down. Try again later.')
Expand Down
4 changes: 2 additions & 2 deletions socketIO_client_nexus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,15 @@ class SocketIO(EngineIO):
- Pass query params, headers, cookies, proxies as keyword arguments.
SocketIO(
'localhost', 8000,
'127.0.0.1', 8000,
params={'q': 'qqq'},
headers={'Authorization': 'Basic ' + b64encode('username:password')},
cookies={'a': 'aaa'},
proxies={'https': 'https://proxy.example.com:8080'})
"""

def __init__(
self, host='localhost', port=None, Namespace=SocketIONamespace,
self, host='127.0.0.1', port=None, Namespace=SocketIONamespace,
wait_for_connection=True, transports=TRANSPORTS,
resource='socket.io', hurry_interval_in_seconds=1, **kw):
self._namespace_by_path = {}
Expand Down
2 changes: 1 addition & 1 deletion socketIO_client_nexus/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def on_event(self, event, *args):
- Call socketIO.on()
socketIO = SocketIO('localhost', 8000)
socketIO = SocketIO('127.0.0.1', 8000)
socketIO.on('my_event', my_function)
- Call namespace.on()
Expand Down
2 changes: 1 addition & 1 deletion socketIO_client_nexus/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ..exceptions import ConnectionError


HOST = 'localhost'
HOST = '127.0.0.1'
PORT = 9000
DATA = 'xxx'
PAYLOAD = {'xxx': 'yyy'}
Expand Down
2 changes: 1 addition & 1 deletion socketIO_client_nexus/tests/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io('//localhost:8000');
var socket = io('//127.0.0.1:8000');
var chat = io('/chat');
var news = io('/news');

Expand Down
2 changes: 1 addition & 1 deletion socketIO_client_nexus/tests/proxy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var proxy = require('http-proxy').createProxyServer({
target: {host: 'localhost', port: 9000}
target: {host: '127.0.0.1', port: 9000}
}).on('error', function(err, req, res) {
console.log('[ERROR] %s', err);
res.end();
Expand Down

0 comments on commit 1117aad

Please sign in to comment.