TCP client & server: connection refused/ permission denied

Hi, I am using these codes:

#!/usr/bin/python3

import socket

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

host = socket.gethostname()

host_ip = socket.gethostbyname(host)

port = 444

clientsocket.connect((host_ip, port))

message = clientsocket.recv(1024)

clientsocket.close()

print(message.decode('ascii'))

for tcpclient.py following the tutorial; https://www.freecodecamp.org/learn/information-security/python-for-penetration-testing/creating-a-tcp-client

However, when I ran it, it said “clientsocket.connect((host_ip, port))
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
ConnectionRefusedError: [Errno 61] Connection refused”

I am very confused. If someone could give some guidance please!! Thank you!

Hi @yuchan.yan,

A server socket must be running to initiate client requests to it. In that video, they go over setting up a server instance and a client instance so you will need to combine the two.