We work to put the power of computing and digital making into the hands of people all over the world
You are watching: Connectionrefusederror: [errno 111] connection refused
I"m following the tutorial here https://pymotw.com/2/socket/tcp.html to create a client and a server.When the communication is local (to "localhost" on the same Pi), it works fine.When I try to run the server on a different Pi (and yes, I change "localhost" to the other server name or IP address), I get a Connection refused error:
Code: Select all
Traceback (most recent call last): File "./cli.py", line 12, in sock.connect(server_address) File "/usr/lib/python2.7/socket.py", line 228, in meth return getattr(self._sock,name)(*args)socket.error: Raspberry Pi Foundation UK Registered Charity 1129409
These are two plain vanilla Stretch Lite installations on Pi Zero W"s on the same network.I tried changing the port number to a different port (i.e. that would not collide with a named service), but that did not resolve the problem.I did something like this previously with Perl programs, and I didn"t need to set up anything special to open the ports - so I don"t know what"s happening here.Any ideas?
DougieLawsonPosts: 41687Joined: Sun Jun 16, 2013 11:19 pmLocation: A small cave in deepest darkest Basingstoke, UKContact:WebsiteTwitter
Assuming no firewalls are blocking you then a "connection refused" is always caused by one of two things1. You"re targetting the right IP address. The service on the port you"re connecting to isn"t running2. You"re targetting the wrong IP address.
Languages using left-hand whitespace for syntax are ridiculousDMs sent on Twitter/LinkedIn will be answered next month.Fake doctors - are all on my foes list.The use of crystal balls and mind reading is prohibited.
I"m not sure how to explain this result. It also breaks when connecting on the SAME Pi, if I use the hostname instead of "localhost".See the screen capture.
Terminal on the left is the server process. Terminal on the right is the client.Note that both are running on the same Pi, "footloose".If I tell the client to connect to "localhost" port 6166, it works (as evidenced by the output on both sides).If I tell the client to connect to "footloose" port 6166, I get "Connection refused" and nothing appears on the server side.Same machine, same port, the only thing that"s different is whether I"m referring to it by its hostname or as "localhost".(and, incidentally, I can ping or ssh just fine, so it"s not mistranslating the hostname/IP address):
footloose:/tmp $ ifconfig wlan0wlan0: flags=4163 mtu 1500 inet 192.168.1.127 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::a998:c7cb:90ad:b13e prefixlen 64 scopeid 0x20 ether b8:27:eb:17:a8:04 txqueuelen 1000 (Ethernet) RX packets 8195 bytes 1342790 (1.2 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2894 bytes 455274 (444.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0pi
footloose:/tmp $ ./cli.py 192.168.1.127 6166connecting to 192.168.1.127 port 6166Traceback (most recent call last): File "./cli.py", line 16, in sock.connect(server_address) File "/usr/lib/python2.7/socket.py", line 228, in meth return getattr(self._sock,name)(*args)socket.error:
Well, don"t I feel silly.The server was listening on "localhost" which meant only on the localhost interface.Not the external-facing network.Once I changed the line to:
See more: Pink Concert San Antonio - Pink In Concert With Julia Michaels
Display posts from previous:All posts1 day7 days2 weeks1 month3 months6 months1 yearSort byAuthorPost timeSubjectAscendingDescending
Raspberry Pi Foundation UK Registered Charity 1129409