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.

+40


source to share


9 replies


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.

+27


source


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.

See here.

+5


source


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.

+2


source


if you have a remote server installed on your computer. specify server.py host as "localhost" and port number. then on the client side you must specify the local ip-127.0.0.1 and port number. then his work

0


source


I ran into a similar issue when I was making a call to the REST API using the python library and found that my server went into hibernation which caused this to happen. Once I logged into the server via a remote desktop connection, my API call worked.

0


source


The solution is to use the same IP and port number on both the client and the server. Try using TCP_IP in the client = 'write ip number here' TCP_PORT = write port number here s.connect ((TCP_IP, TCP_PORT))

-1


source


the short term solution is to use a standard iis host and port, usually 120.0.0.1 and 80 respectively. However, I am still looking for a more generic solution.

-1


source


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 .....

      

-1


source


When you run the code on a windows machine, the firewall prompts it to allow network access, allow network access, and it will work if it doesn't ask, go to firewall settings> allow application through firewall and select your python.exe and allow access to the network.

-1


source







All Articles