Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am currently trying to work with python networking and I have reached a bit of a road block. I am not able to network with any computer but localhost, which is kind-of useless with what networking is concerned. I have tried on my local network, from one computer to another, and I have tried over the internet, both fail. The only time I can make it work is if (when running on the server's computer) it's ip is set as 'localhost' or '' (computers ip).

I have spent hours going over opening ports with my isp and have gotten nowhere, so I decided to try this forum. I have my windows firewall down and I have included some pictures of important screen shots. I have no idea what the problem is and this has spanned almost a year of calls to my isp. The computer, modem, and router have all been replaced in that time.

Screen shots:

import socket
import threading
import socketserver

class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):

    def handle(self):
        data = self.request.recv(1024)
        cur_thread = threading.current_thread()
        response = "{}: {}".format(cur_thread.name, data)

class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):

def client(ip, port, message):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((ip, port))
        response = sock.recv(1024)
        print("Received: {}".format(response))

if __name__ == "__main__":
    # Port 0 means to select an arbitrary unused port
    HOST, PORT = "", 9000

    server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
    ip, port = server.server_address

    # Start a thread with the server -- that thread will then start one
    # more thread for each request
    server_thread = threading.Thread(target=server.serve_forever)
    # Exit the server thread when the main thread terminates
    server_thread.daemon = True
    print("Server loop running in thread:", server_thread.name)
    ip = ''
    print(ip, port)

    client(ip, port, b'Hello World 1')
    client(ip, port, b'Hello World 2')
    client(ip, port, b'Hello World 3')


I do not know where the error is occurring. I get this error:

Traceback (most recent call last):
  File "C:\Users\Dr.Frev\Desktop\serverTest.py", line 43, in <module>
    client(ip, port, b'Hello World 1')
  File "C:\Users\Dr.Frev\Desktop\serverTest.py", line 18, in client
    sock.connect((ip, port))
socket.error: [Errno 10061] No connection could be made because the target machine 
actively refused it 

Any help will be greatly appreciated.

*if this isn't a proper forum for this, could someone direct me to a more appropriate one.

share|improve this question

migrated from stackoverflow.com Oct 4 '12 at 9:04

This question came from our site for professional and enthusiast programmers.

Please put your code in the question itself (indented by four characters in each line) rather than linking to a screenshot. –  David Robinson Sep 26 '12 at 0:43
Is this a problem with Python or with your residential internet connection? –  nneonneo Sep 26 '12 at 0:45
What does pinging the machines on your local network from the console show? –  Dave Sep 26 '12 at 1:11
When I ping a computer that is wireless it times out, when I ping a computer that is wired to the modem it works fine. –  user1642826 Sep 26 '12 at 1:20
@user1642826 Then the problem is your wireless setup. –  Marcin Sep 26 '12 at 1:36

2 Answers 2

I do not understand your config. Your server is on But your client tries to connect to: ip = ''? Your client and server should be on the same lan subnet

share|improve this answer is the machine it is on, ip = '' is my ip, for my network. Python doesn't let me put my server on '', because that's my modem's outside ip. –  user1642826 Sep 26 '12 at 1:37
But you must have a server and client runnning on the same local subnet. What is the ip of the server and what is the ip of your client? –  voscausa Sep 26 '12 at 1:45
@user1642826: That's not possible, since "789" is not a valid quad for an ipv4 address. –  Daenyth Sep 26 '12 at 16:13
@Daenyth <- is not my ip address, its 1-9 in the ip format. –  user1642826 Sep 27 '12 at 1:20

i know what from U: 1,ip is your modem's outside ip. ip of you test PC is 2,your server listen on which is this test PC 3,now you want to run a client to connect to

if all i see is the fact, something wrong under: 1,server run on test pc can't listen on your modem's port which you want (,it just listen on local pc 2, due to 1. the tcp port on modem your client connect to is not be listened. so sock.connect((ip, port)) in client function rasie the error you got .

as i see, you may seperate client and server, let server listen on a solid ip(eg., then make client to connect to the port what server listen on. i guess it can work

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.