Errno 10061: The connection could not be made because the target machine actively refused it (client-server)
I have a problem with these client and server codes, I keep getting [Errno 10061]. No connection can be made because the target machine has actively refused it
I am running a server in a Windows XP SP3 virtual machine and a client on Windows 7 64bit, my python version is 2.7.3. I want to know how to change the code to use client and server on different networks! Thank you!
server:
#!/usr/bin/python # This is server.py file
import socket # Import socket module
s = socket.socket() # Create a socket object
host = '0.0.0.0' # Get local machine name
port = 12345 # Reserve a port for your service.
print 'Server started!'
print 'Waiting for clients...'
s.bind((host, port)) # Bind to the port
s.listen(5) # Now wait for client connection.
c, addr = s.accept() # Establish connection with client.
print 'Got connection from', addr
while True:
msg = c.recv(1024)
print addr, ' >> ', msg
msg = raw_input('SERVER >> ')
c.send(msg);
#c.close() # Close the connection
customer:
#!/usr/bin/python # This is client.py file
import socket # Import socket module
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
print 'Connecting to ', host, port
s.connect((host, port))
while True:
msg = raw_input('CLIENT >> ')
s.send(msg)
msg = s.recv(1024)
print 'SERVER >> ', msg
#s.close # Close the socket when done
PS: the code is from the internet.
source to share
10061 WSAECONNREFUSED, "connection refused", which means nothing was listening on the IP port you were trying to connect to.
In 2000, a firewall product was released that bounced instead of ignoring incoming connections on blocked ports, but this was quickly found to be an information leak to attackers and fixed or canceled.
source to share
Hint: actively refused
sounds a little deeper than technical issues, but ...
... in fact, this answer (and also specifically errno:10061
) is also provided if you are calling the bin / mongo executable and the mongodb service just doesn't work on the target machine. This even applies to local machine instances (everything happens on localhost).
➪ Always rule out this trivial possibility first , i.e. just using a command line client to access your db.
source to share
Using examples from: https://docs.python.org/3.2/library/socketserver.html I figured I needed to install the HOST port on the machine where the server program was running. So TCPServer at 192.168.0.1 HOST = TCPServer IP 192.168.0.1, then I had to set the TCPClient side to point to TCPServer's IP. So HOSTClickClick value = 192.168.0.1 - Sorry, this is the best I can describe.
source to share
This could be due to a proxy or firewall. If it is a proxy, then you need to specify the proxy settings at the entry point of your code or project.
import os #for proxy
proxy = 'http://10.XX.XX.XX:8X8X' #your own proxy 'http://<user>:<pass>@<proxy>:<port>'
os.environ['http_proxy'] = proxy
os.environ['HTTP_PROXY'] = proxy
os.environ['https_proxy'] = proxy
os.environ['HTTPS_PROXY'] = proxy
#rest of code .....
source to share