PyCharm blocking client socket connection (windows)

I have some simple unit tests where I am making a server/client socket connection on a specified port. When I run this test through the PyCharm Python debugger, I get an error message related to a connection refusal. 



ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it



My first instinct was that this was not a PyCharm issue, but I can run these tests in VsCode perfectly fine. From what I can tell, the only difference between my VsCode debugger setup vs PyCharm is my launch.json file. 




    "version": "0.2.0",

    "configurations": [


            "name": "Python Debugger: Current File",

            "type": "debugpy",

            "request": "launch",

            "program": "${file}",

            "console": "integratedTerminal"






I don't know if there are any other settings in PyCharm that I can manipulate to perfectly emulate the VsCode settings from the launch.json file. To add even more mystery, if I restart my computer and run the tests in PyCharm, they will pass the first time, but if I run them again, they will fail for the connection refusal. I've checked if there are any hanging connections in the terminal on the port I've been using but there is nothing..


I really want to be able to use PyCharm but this would obviously be a huge deal breaker. We need to be able to test our code that uses these socket connections but there seems to be some issue with how the PyCharm python debugger operates?

# Example of how I start the server; 

cls.server_process = multiprocessing.Process(target=start_server)


# connect the client
cls.socket_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
cls.socket_client.connect(('localhost', 9999))
Actually, there is nothing that can block a port from the PyCharm's debugger. 
At first, I suspected Windows Firewall (as a common source of most network issues on Windows), but since the test ran well for the first time, it doesn't seem to be the reason here. However, I would suggest doing the following to test if the port is accessible from other applications: 
1. Download ncat ( for Windows (part of the nmap package).
2. Start a listener: ncat -lv 9999
3. Open another command line window and try connecting ncat -v 9999
4. If it says connection is successfull, try typing something and make sure the input is reflected in both command line windows.

Another thing is that "connection actively refused" might be a sign that nothing listens on the port, which is complicated to troubleshoot without a project sample. Is it possible to provide a simplified version of your project so we can test it?