'error: [Errno 10061] No connection could be made because the target machine actively refused it

I was building a simple client/server code and i keep getting this error. I dont understand why (I am trying to get used to python). here is my code:

Server Code:

import socket
from socket import*
from time import ctime

HOST = ''
PORT = 21567
BUFSIZ = 1024
ADDR =(HOST, PORT)

tcpsersock = socket(AF_INET, SOCK_STREAM)
tcpsersock.bind(ADDR)
tcpsersock.listen(5)

while True:
    print("waiting for connection...")
    tcpclisock, addr = tcpsersock.accpet()
    print("...Connected from: "),addr

    while True:
        data = tcpclisock.recv(BUFSIZ)
        if not data:
            break
        tcpclisock.send('[%s] %s' %(ctime(), data))

    tcpclisock.close()
tcpsersock.close()

Client Code:

import socket
from socket import*
from time import ctime

HOST = 'localhost'
PORT = 21567
BUFSIZ = 1024
ADDR = (HOST, PORT)

tcpclisock = socket(AF_INET, SOCK_STREAM)
tcpclisock.connect(ADDR)

while True:
    data = raw_input('> ')
    if not data:
        break
    tcpclisock.send(data)
    data = tcpclisock.recv(BUFSIZ)
    if not data:
        break
    print data

tcpclisock.close()

I get this error:

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


Solution 1:[1]

Try this:

tcpclisock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

This is almost straight from the documents page for socket which you can find here socket

Solution 2:[2]

Probably there is no server process running on the server side (due to accpet()?)

Solution 3:[3]

That suggests the remote machine has received your connection request, and send back a refusal (a RST packet). I don't think this is a case of the remote machine simply not having a process listening on that port (but i could be wrong!).

That sounds like a firewall problem. It could be a firewall on the remote machine, or a filter in the network in between, or, perhaps on your local machine - are you running any kind of security software locally?

Solution 4:[4]

first run the server script -- which starts listening then open the client .. or -- try to change the port the error simply indicates "that no one is listening"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pistache
Solution 2 glglgl
Solution 3 Tom Anderson
Solution 4 rogue_leader