Hack Forums
[Python] ConnectionRefusedError: [Errno 111] Connection refused - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] ConnectionRefusedError: [Errno 111] Connection refused (/showthread.php?tid=5688790)



ConnectionRefusedError: [Errno 111] Connection refused - PimpSlickback - Aug 7, 2017

Here's what I'm trying to do
1. Write a TCP Client that will connect to 127.0.0.1 on port 9990.
2. send "Hello, World" to the server.
3. get the response, and print it out.

Here is my code:

[Image: cywbGmw.png]

Code
from time import sleep
import socket

c_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
c_socket.connect(('127.0.0.1', 9990))
c_socket.send('hello, world')
test = c_socket.recv(1024)
print(test)


s_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s_socket.bind(("127.0.0.1", 9990))
s_socket.listen(10)


while True:
    connection, address = s_socket.accept()
    test = connection.recv(1024)
    if len(test) > 0:
        print(test)

    
    connection.close()
    break


s_socket.close()

sleep(0.05)



* - vorticalbox - Aug 7, 2017

Do you have a firewall? I believe windows firewall blocks incoming connections by default.


* - PimpSlickback - Aug 7, 2017

(Aug 7, 2017 11:54 AM)vorticalbox Wrote:  Do you have a firewall? I believe windows firewall blocks incoming connections by default.

I dont think it's the firewall because when i do the same code for port 9987 is works, but I need port 9990


* - Payload - Aug 7, 2017

(Aug 7, 2017 11:57 AM)PimpSlickback Wrote:  I dont think it's the firewall because when i do the same code for port 9987 is works, but I need port 9990

It works for me on ports I have allowed TCP inbound/outbound on the firewall. You probably just have to do that, if it still doesn't work you have something blocking that port, on windows try.

Code
netstat -na | find "9990"

to see what is running on that port.


* - PimpSlickback - Aug 7, 2017

(Aug 7, 2017 12:22 PM)Payload Wrote:  It works for me on ports I have allowed TCP inbound/outbound on the firewall. You probably just have to do that, if it still doesn't work you have something blocking that port, on windows try.

Code
netstat -na | find "9990"

to see what is running on that port.

This is on a website for a test so it won't allow me to see/do any of that. It only gives me the directions above. So port 9990 should be open unless I am missing some line of code somewhere.