Take the 2-minute tour ×

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

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)

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

    # 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
    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
show 5 more comments

2 Answers

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
add comment

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
add comment

Your Answer

