Help: "ConnectionRefusedError: [Errno 61] Connection refused"
Everytime on run this TCP Client script on my iPhone i get the error message from the title. Any ideas why? The script works fine on Windows.
import socket TCP_IP = '127.0.0.1' TCP_PORT = 5005 BUFFER_SIZE = 1024 MESSAGE = "Hello, World" s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((TCP_IP,TCP_PORT)) s.send(MESSAGE.encode('utf-8')) data = s.recv(BUFFER_SIZE) s.close() print("recived data: ", data.decode('utf-8'))
BTW! I'm executing it with Python 3.6.
What are you trying to connect to with the socket? 127.0.0.1 is the loopback address, so you're connecting to the device that the script is running on (in this case, your iPhone). The connection is refused because nothing on your iPhone is listening on port 5005.
If you have another script on your Windows computer that listens on port 5005, and you want to connect to that from your iPhone, you need to use your Windows computer's local IP address instead of 127.0.0.1.
Thank you for your reply. Your answer solved my problem.