Connection Refused (to client)

552 views
Skip to first unread message

Ryne Everett

unread,
Oct 9, 2014, 4:21:04 PM10/9/14
to ws...@googlegroups.com
Whenever I try to start a client I get a ConnectionRefusedError (this is python3; when trying it in python2 I get the equivalent socket.error). Here are the steps that raise the error:
  1. Start the cherrypy server from documentation in one shell.
  2. Start the builtin client from documentation in another shell.
When I start the client the following error is raised in the second shell:

python2
Traceback (most recent call last):
  File "wsclient2.py", line 28, in <module>
    ws.connect()
  File "/home/ryne/.virtualenvs/ws2/lib/python2.7/site-packages/ws4py/client/__init__.py", line 209, in connect
    self.sock.connect(self.bind_addr)
  File "/usr/lib64/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 111] Connection refused

python3
Traceback (most recent call last):
  File "wsclient.py", line 14, in <module>
    ws.connect()
  File "/home/ryne/.virtualenvs/ws3/lib/python3.4/site-packages/ws4py/client/__init__.py", line 209, in connect
    self.sock.connect(self.bind_addr)
ConnectionRefusedError: [Errno 111] Connection refused

The first shell running the server logs nothing when this happens.

I have a feeling I'm just doing something stupid, because I get the same errors when I try this tutorial (which is closer to what I'm actually trying to achieve).

Sylvain Hellegouarch

unread,
Oct 9, 2014, 4:25:32 PM10/9/14
to ws...@googlegroups.com
Hi there,

There is no such thing as doing something stupid. We always begin somewhere :)

Now, the error is probably coming from the fact your server will serve websockets at ws://localhost:9000/ws but your client tries to connect via ws://localhost:9000/
See the missing "ws". 

Simply change the client to point at ws://localhost:9000/ws and it should work. 

--
- Sylvain
http://www.defuze.org
http://twitter.com/lawouach

Ryne Everett

unread,
Oct 9, 2014, 4:30:15 PM10/9/14
to ws...@googlegroups.com
That's a good point, but I still get the same errors.

Sylvain Hellegouarch

unread,
Oct 9, 2014, 4:32:19 PM10/9/14
to ws...@googlegroups.com
2014-10-09 22:30 GMT+02:00 Ryne Everett <rynee...@gmail.com>:
That's a good point, but I still get the same errors.



Hmm, your error indicates the address cannot even be reached. Could you paste the server logs here please? I assume they are both on the same host right? 

Ryne Everett

unread,
Oct 9, 2014, 4:39:07 PM10/9/14
to ws...@googlegroups.com
Yes, I'm doing this all locally.

[09/Oct/2014:16:37:13] ENGINE Listening for SIGHUP.
[09/Oct/2014:16:37:13] ENGINE Listening for SIGTERM.
[09/Oct/2014:16:37:13] ENGINE Listening for SIGUSR1.
[09/Oct/2014:16:37:13] ENGINE Bus STARTING
[09/Oct/2014:16:37:13] ENGINE Starting WebSocket processing
[09/Oct/2014:16:37:13] ENGINE Started monitor thread 'Autoreloader'.
[09/Oct/2014:16:37:13] ENGINE Started monitor thread '_TimeoutMonitor'.
[09/Oct/2014:16:37:13] ENGINE Serving on http://127.0.0.1:9000
[09/Oct/2014:16:37:13] ENGINE Bus STARTED
^C[09/Oct/2014:16:37:28] ENGINE Keyboard Interrupt: shutting down bus
[09/Oct/2014:16:37:28] ENGINE Bus STOPPING
[09/Oct/2014:16:37:28] ENGINE HTTP Server cherrypy._cpwsgi_server.CPWSGIServer(('127.0.0.1', 9000)) shut down
[09/Oct/2014:16:37:28] ENGINE Terminating WebSocket processing
[09/Oct/2014:16:37:28] ENGINE Stopped thread 'Autoreloader'.
[09/Oct/2014:16:37:28] ENGINE Stopped thread '_TimeoutMonitor'.
[09/Oct/2014:16:37:28] ENGINE Bus STOPPED
[09/Oct/2014:16:37:28] ENGINE Bus EXITING
[09/Oct/2014:16:37:28] ENGINE Bus EXITED
[09/Oct/2014:16:37:28] ENGINE Waiting for child threads to terminate...

Sylvain Hellegouarch

unread,
Oct 9, 2014, 4:43:50 PM10/9/14
to ws...@googlegroups.com
2014-10-09 22:39 GMT+02:00 Ryne Everett <rynee...@gmail.com>:
Yes, I'm doing this all locally.

[09/Oct/2014:16:37:13] ENGINE Listening for SIGHUP.
[09/Oct/2014:16:37:13] ENGINE Listening for SIGTERM.
[09/Oct/2014:16:37:13] ENGINE Listening for SIGUSR1.
[09/Oct/2014:16:37:13] ENGINE Bus STARTING
[09/Oct/2014:16:37:13] ENGINE Starting WebSocket processing
[09/Oct/2014:16:37:13] ENGINE Started monitor thread 'Autoreloader'.
[09/Oct/2014:16:37:13] ENGINE Started monitor thread '_TimeoutMonitor'.
[09/Oct/2014:16:37:13] ENGINE Serving on http://127.0.0.1:9000
[09/Oct/2014:16:37:13] ENGINE Bus STARTED
^C[09/Oct/2014:16:37:28] ENGINE Keyboard Interrupt: shutting down bus
[09/Oct/2014:16:37:28] ENGINE Bus STOPPING
[09/Oct/2014:16:37:28] ENGINE HTTP Server cherrypy._cpwsgi_server.CPWSGIServer(('127.0.0.1', 9000)) shut down
[09/Oct/2014:16:37:28] ENGINE Terminating WebSocket processing
[09/Oct/2014:16:37:28] ENGINE Stopped thread 'Autoreloader'.
[09/Oct/2014:16:37:28] ENGINE Stopped thread '_TimeoutMonitor'.
[09/Oct/2014:16:37:28] ENGINE Bus STOPPED
[09/Oct/2014:16:37:28] ENGINE Bus EXITING
[09/Oct/2014:16:37:28] ENGINE Bus EXITED
[09/Oct/2014:16:37:28] ENGINE Waiting for child threads to terminate...



Would you mind trying by using ws://127.0.0.1:9000/ws instead of localhost. Just want to make sure it's not your /etc/hosts which is causing trouble.


Ryne Everett

unread,
Oct 9, 2014, 5:00:41 PM10/9/14
to ws...@googlegroups.com
Thanks, that's all it took to make the example's from the documentation work! It would be great to see those two changes incorporated into the docs so there's a working, cut-and-pastable example.

Unfortunately I first ran into these errors while using the explicit address, but hopefully having a working example will be enough to debug my use case.

Also, do you think my /etc/hosts is misconfigured? Looks pretty normal to me:
#
# /etc/hosts: static lookup table for host names
#

#<ip-address> <hostname.domain.org> <hostname>
127.0.0.1 localhost.localdomain localhost UncleGlitter
::1 localhost.localdomain localhost

# End of file

Thanks for the help.

Sylvain Hellegouarch

unread,
Oct 9, 2014, 5:05:48 PM10/9/14
to ws...@googlegroups.com
2014-10-09 23:00 GMT+02:00 Ryne Everett <rynee...@gmail.com>:
Thanks, that's all it took to make the example's from the documentation work! It would be great to see those two changes incorporated into the docs so there's a working, cut-and-pastable example.


Good point. I will try to think about it.

 

Unfortunately I first ran into these errors while using the explicit address, but hopefully having a working example will be enough to debug my use case.

Also, do you think my /etc/hosts is misconfigured? Looks pretty normal to me:
#
# /etc/hosts: static lookup table for host names
#

#<ip-address> <hostname.domain.org> <hostname>
127.0.0.1 localhost.localdomain localhost UncleGlitter
::1 localhost.localdomain localhost

# End of file

Thanks for the help.


It's fine but I'm wondering if your OS doesn't use IPv6 with a higher priority here whereas on the server side, it was by default binding to an IPv4 address.

Reply all
Reply to author
Forward
0 new messages