Skip to content

Commit 1e58add

Browse files
Replace localhost with explicit 127.0.0.1
1 parent 9a78f52 commit 1e58add

6 files changed

Lines changed: 18 additions & 18 deletions

File tree

README.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Emit. ::
5151

5252
from socketIO_client import SocketIO, LoggingNamespace
5353

54-
with SocketIO('localhost', 8000, LoggingNamespace) as socketIO:
54+
with SocketIO('127.0.0.1', 8000, LoggingNamespace) as socketIO:
5555
socketIO.emit('aaa')
5656
socketIO.wait(seconds=1)
5757

@@ -62,7 +62,7 @@ Emit with callback. ::
6262
def on_bbb_response(*args):
6363
print('on_bbb_response', args)
6464

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

@@ -82,7 +82,7 @@ Define events. ::
8282
def on_aaa_response(*args):
8383
print('on_aaa_response', args)
8484

85-
socketIO = SocketIO('localhost', 8000, LoggingNamespace)
85+
socketIO = SocketIO('127.0.0.1', 8000, LoggingNamespace)
8686
socketIO.on('connect', on_connect)
8787
socketIO.on('disconnect', on_disconnect)
8888
socketIO.on('reconnect', on_reconnect)
@@ -114,7 +114,7 @@ Define events in a namespace. ::
114114
print('on_aaa_response', args)
115115
self.emit('bbb')
116116

117-
socketIO = SocketIO('localhost', 8000, Namespace)
117+
socketIO = SocketIO('127.0.0.1', 8000, Namespace)
118118
socketIO.emit('aaa')
119119
socketIO.wait(seconds=1)
120120

@@ -133,7 +133,7 @@ Define standard events. ::
133133
def on_disconnect(self):
134134
print('[Disconnected]')
135135

136-
socketIO = SocketIO('localhost', 8000, Namespace)
136+
socketIO = SocketIO('127.0.0.1', 8000, Namespace)
137137
socketIO.wait(seconds=1)
138138

139139
Define different namespaces on a single socket. ::
@@ -150,7 +150,7 @@ Define different namespaces on a single socket. ::
150150
def on_aaa_response(self, *args):
151151
print('on_aaa_response', args)
152152

153-
socketIO = SocketIO('localhost', 8000)
153+
socketIO = SocketIO('127.0.0.1', 8000)
154154
chat_namespace = socketIO.define(ChatNamespace, '/chat')
155155
news_namespace = socketIO.define(NewsNamespace, '/news')
156156

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

165165
# Skip server certificate verification
166-
SocketIO('https://localhost', verify=False)
166+
SocketIO('https://127.0.0.1', verify=False)
167167
# Verify the server certificate
168-
SocketIO('https://localhost', verify='server.crt')
168+
SocketIO('https://127.0.0.1', verify='server.crt')
169169
# Verify the server certificate and encrypt using client certificate
170-
socketIO = SocketIO('https://localhost', verify='server.crt', cert=(
170+
socketIO = SocketIO('https://127.0.0.1', verify='server.crt', cert=(
171171
'client.crt', 'client.key'))
172172

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

178178
SocketIO(
179-
'localhost', 8000,
179+
'127.0.0.1', 8000,
180180
params={'q': 'qqq'},
181181
headers={'Authorization': 'Basic ' + b64encode('username:password')},
182182
cookies={'a': 'aaa'},
@@ -186,7 +186,7 @@ Wait forever. ::
186186

187187
from socketIO_client import SocketIO
188188

189-
socketIO = SocketIO('localhost', 8000)
189+
socketIO = SocketIO('127.0.0.1', 8000)
190190
socketIO.wait()
191191

192192
Don't wait forever. ::
@@ -195,7 +195,7 @@ Don't wait forever. ::
195195
from socketIO_client import SocketIO
196196

197197
try:
198-
socket = SocketIO('localhost', 8000, wait_for_connection=False)
198+
socket = SocketIO('127.0.0.1', 8000, wait_for_connection=False)
199199
socket.wait()
200200
except ConnectionError:
201201
print('The server is down. Try again later.')

socketIO_client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,15 @@ class SocketIO(EngineIO):
334334
- Pass query params, headers, cookies, proxies as keyword arguments.
335335
336336
SocketIO(
337-
'localhost', 8000,
337+
'127.0.0.1', 8000,
338338
params={'q': 'qqq'},
339339
headers={'Authorization': 'Basic ' + b64encode('username:password')},
340340
cookies={'a': 'aaa'},
341341
proxies={'https': 'https://proxy.example.com:8080'})
342342
"""
343343

344344
def __init__(
345-
self, host='localhost', port=None, Namespace=SocketIONamespace,
345+
self, host='127.0.0.1', port=None, Namespace=SocketIONamespace,
346346
wait_for_connection=True, transports=TRANSPORTS,
347347
resource='socket.io', hurry_interval_in_seconds=1, **kw):
348348
self._namespace_by_path = {}

socketIO_client/namespaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def on_event(self, event, *args):
116116
117117
- Call socketIO.on()
118118
119-
socketIO = SocketIO('localhost', 8000)
119+
socketIO = SocketIO('127.0.0.1', 8000)
120120
socketIO.on('my_event', my_function)
121121
122122
- Call namespace.on()

socketIO_client/tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ..exceptions import ConnectionError
88

99

10-
HOST = 'localhost'
10+
HOST = '127.0.0.1'
1111
PORT = 9000
1212
DATA = 'xxx'
1313
PAYLOAD = {'xxx': 'yyy'}

socketIO_client/tests/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script src="/socket.io/socket.io.js"></script>
22
<script>
3-
var socket = io('//localhost:8000');
3+
var socket = io('//127.0.0.1:8000');
44
var chat = io('/chat');
55
var news = io('/news');
66

socketIO_client/tests/proxy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var proxy = require('http-proxy').createProxyServer({
2-
target: {host: 'localhost', port: 9000}
2+
target: {host: '127.0.0.1', port: 9000}
33
}).on('error', function(err, req, res) {
44
console.log('[ERROR] %s', err);
55
res.end();

0 commit comments

Comments
 (0)