Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errno 10061 : No connection could be made because the target machine actively refused it ( client - server )

Tags:

python

sockets

I have a problem with these client and server codes, I keep getting the [Errno 10061] No connection could be made because the target machine actively refused it

I'm running the server on a virtual machine with Windows XP SP3 and the client on Windows 7 64bit, my python version is 2.7.3. What I want to know is how should I edit the code to use the client and server on different networks! Thanks!

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

client :

#!/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 : code is from internet.

like image 377
havox Avatar asked Oct 20 '12 22:10

havox


People also ask

How do you fix 10061 No connection could be made because the target machine actively refused it?

1-Disable WMI services : run - services. msc - Windows Management Instrumentation(WMI) - stop the service. 2-Delete the files under C:\Windows\System32\wbem\Repository 3-Open regedit: Go to HKEY_LOCAL_MACHINE > Software and HKEY_CURRENT_USER > Software.

Can't connect to error 10061 connection?

The 10061 is a winsock connection error meaning the connection was refused. No connection could be made because the target machine actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host i.e. one with no server application running.


4 Answers

10061 is WSAECONNREFUSED, 'connection refused', which means there was nothing listening at the IP:port you tried to connect to.

There was a firewall product around the year 2000 that issued refusals instead of ignoring incoming connections to blocked ports, but this was quickly recognised as an information leak to attackers and corrected or withdrawn.

like image 136
user207421 Avatar answered Oct 13 '22 21:10

user207421


Hint: actively refused sounds like somewhat deeper technical trouble, but...

...actually, this response (and also specifically errno:10061) is also given, if one calls the bin/mongo executable and the mongodb service is simply not running on the target machine. This even applies to local machine instances (all happening on localhost).

Always rule out for this trivial possibility first, i.e. simply by using the command line client to access your db.

See here.

like image 40
Frank Nocke Avatar answered Oct 13 '22 20:10

Frank Nocke


Using the examples from: https://docs.python.org/3.2/library/socketserver.html I determined that I needed to set the HOST port to the machine I had the server program running on. So TCPServer on 192.168.0.1 HOST = TCPServer IP 192.168.0.1 then I had to set the TCPClient side to point to the TCPServer IP. So the TCPClient HOST value = 192.168.0.1 - Sorry, that's the best I can describe it.

like image 3
purza95 Avatar answered Oct 13 '22 19:10

purza95


So I was facing the same issue, and the solution that worked for me was...

I am assuming your server and client program are written in python.

  1. First, open one python shell
  2. open and run the Server program first
  3. then open another different python shell
  4. open and run the Client program here
  5. done !!
like image 3
rv_power Avatar answered Oct 13 '22 20:10

rv_power