I am having problems with my code in a simple One-client -- server communication. Running it from my local machine (desktop pc) seems to run just fine, but, when I used my desktop as a server and my laptop as a client I was getting WinError 10061... "No connection could be made because the machine actively refused it"
I followed some advice from other questions here , this question and here but I still have questions.
Code is below:
Server:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("myIPaddress", 4000))
s.listen(5)
.
.
. #rest of the code
Client:
import socket
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = "myIPaddress"
s.connect((host, 4000))
.
.
. #rest of code
What I want to do is the server to detect and bind to any client's IP address, and the client to connect to the server without having to specify an IP address. Is this possible? It worked with the following ways:
- putting in bind (server.py) and connect(client.py) the IP address.
- putting my IP address only in client and using socket.gethostname() in the server
It didn't work with: binding and connecting to '0.0.0.0'. I still got the Error 10061. The Member Polynomial in here, gave a pretty undestandable explanation, but it didn't work for me and I have yet to grasp the idea of how to leave the socket accessible to all. The same goes when entering the '127.0.0.1' address. What am I doing wrong?