Programmers learn & share
0 votes
728 views

Problem :

I am facing the issue with the client and server codes, I keep on getting the [Errno 10061] No connection could be made because the target machine actively refused it

I am running the server on a VM with Windows XP SP3 and my client is on Windows 7 64bit, also my python version is 2.7.3. I want to know is how can I edit the existing code to be able to use the client and server on different networks.

My server code:

#!/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

My client code :

#!/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
by (6.9k points)   | 728 views

1 Answer

0 votes

Solution :

1) You need to first change directory to root drive C:\, and type the following command into an admin cmd prompt window,

C:\mongodb\bin\mongod.exe --config c:\mongodb\mongod.cfg –install

2) After that type net start MongoDB after which you must see the following message:

"The Mongo DB service was started successfully"

3) Then go to the your control panel and go to Start>Administrative Tools>Services, scroll down up to MongoDB in the list of services and please make sure you change the start up type to automatic. Press OK.

4) Finally you need to type C:\mongodb\bin\mongo.exe and you will be connected to the Mongo test DB.

And your issue will be resolved.

by (36.1k points)  
2,227 questions
2,734 answers
59 comments
241 users