Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

ConnectionRefusedError: [Errno 111] Connection refused

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)
Do you have a firewall? I believe windows firewall blocks incoming connections by default.

¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´
(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
(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.
[Image: 4YPLYme.gif]

(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.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Shell] by HardRockOct 28, 2019 11:45 PM 3 216 Oct 28, 2019 11:45 PM
Last Post: HardRock
[Python] by SIM-2427156Apr 26, 2017 06:40 PM 5 150 Apr 26, 2017 06:40 PM
Last Post: (╯°□°)╯︵ ┻━━┻
[Python] by SkidyApr 13, 2017 03:16 AM 2 138 Apr 13, 2017 03:16 AM
Last Post: Skidy