Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/Questions/Connectionrefusederror: [errno 61] connection refused - simple way to solve it
Next
Answered
Patricia O'Sullivan
  • 8
Patricia O'Sullivan
Asked: May 18, 20222022-05-18T21:17:52+00:00 2022-05-18T21:17:52+00:00In: python

Connectionrefusederror: [errno 61] connection refused – simple way to solve it

  • 8

Hi developer experts,
I have a small but frustrating use case, and so far, I couldn’t get my head around this problem & ideal solution. I am running my command and facing one problem with the connectionrefusederror: [errno 61] connection refused.
Below is the command I used:

import socket
 
 def socket_create():
 try:
 
  global host
  global port
  global s
  host = ''
  port = 9999
  s = socket.socket()
 
 except socket.error as msg:
  print("Socket creation error" + str(msg))
 
 #Wait for client, Connect socket and port
 def socket_bind():
 try:
  global host
  global port
  global s
  print("Binding socket to port: " + str(port)) 
  s.bind((host, port))
  s.listen(5)
 except socket.error as msg:
  print("Socket binding error" + str(msg) + "\n" + "Retrying...")
  socket_bind
 
 #Accept connections (Establishes connection with client) socket has to be listining
 def socket_accept():
  conn, address = s.accept()
  print("Connection is established |" + " IP:" + str(address[0]) + "| port:" + str(address[1]))
 chat_send(conn)
 
 
 def chat_send(conn):
  while True:
  chat =input()
  if len(str.encode(chat)) > 0:
  conn.send(str.encode(chat))
  client_response = str(conn.recv(1024), "utf-8")
  print(client_response)
 def main():
 socket_create()
 socket_bind()
 socket_accept()
 
 main()
import socket
 
 
 #connects to server
 s = socket.socket()
 host = '127.0.0.1'
 port = 9999
 s.connect((host, port))
 
 #gets chat
 while True:
  data = s.recv(1024)
  print (data[:].decode("utf-8")) 
  chat = input()
  s.send(str.encode(chat))

When I run it, I get the following error:

ConnectionRefusedError: [Errno 61] Connection refused

I am looking forward to gaining some knowledge from all experts.
Thank you, guys!

errno 61 connection refused
  • 2 2 Answers
  • 664 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    lyytutoria Expert
    2022-06-29T10:47:26+00:00Added an answer on June 29, 2022 at 10:47 am

    The cause:

    You have encountered this error because you are not using the same networks. They are different, so client cannot connect with server on the same network or computer. Therefore, the error happens.

    Solution:

    You have to provide your client a IP from server, such as 192.168.0.1.

    Let’s check your server:

    If it’s in console on Linux:

    ifconfig

    In the case, it’s in cmd.exe on Windows:

    ipconfig

    Ipconfig/ifconfig returns a local IP address that is only accessible within the local network, such as 192.168.0.1. Then your router and the routers of the service provider may need external IP and setup (redirections). External IP can be the router’s or your service provider’s IP. When you access to websites like http://httpbin.org/ip , you may see your external IP address. However, it can still need more development and pose a bigger issue.  

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Louise Bouquet
    2022-05-25T21:17:13+00:00Added an answer on May 25, 2022 at 9:17 pm

    Although this may not be the answer to your original question, I did encounter the error. It was because I didn’t start the server process to listen to localhost (127.0.0.1), on the port I wanted to test. To allow the client to connect on localhost, the server must be listening to localhost.

    • 6
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.