Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 socket programming ConnectionRefusedError error
#1
I am working with IDLE for python 3.7.2
when i am trying to get connected through socket programming between server and client
through IDLE shell it gives me following error
Traceback (most recent call last):
File "C:/Users/Administrator/AppData/Local/Programs/Python/Python37/Client4.py", line 13, in <module>
s.connect((host, port))
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

but the it is connected through command prompt then it is working fine....

Can anybody explain???
buran wrote May-13-2019, 11:51 AM:
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
Quote
#2
It would probably help if you post also your code
Quote
#3
(May-13-2019, 11:54 AM)buran Wrote: It would probably help if you post also your code

server 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.
s.bind((host, port))        # Bind to the port
s.listen(5)                 # Now wait for client connection.
while True:
   c, addr = s.accept()     # Establish connection with client.
   print ('Got connection from' ,addr)
   
   c.send("Thank you for connecting")
  
   c.close()
client 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.
s.connect((host, port))
print (s.recv(1024))

s.close()                     # Close the socket when done
error is
Error:
Traceback (most recent call last): File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Client1.py", line 6, in <module> s.connect((host, port)) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it >>>
micseydel wrote May-15-2019, 10:20 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#4
Change host to host = 'localhost' on client.
When you try to get the socket host name the socket first needs a host. If you are not connected to a server, there is no host to return a host name. The socket is just an empty socket until you connect to a server. If the client and server are on the same computer host will be 'localhost' I do't know yet what you do if they are on different computers. Also you need to do this:
from socket import socket, AF_INET, SOCK_STREAM
sock = socket(AF_INET, SOCK_STREAM)
You might also need to change host = '' on the server code.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  socket.gaierror: [Errno -2] Name or service not known seokangwoo99 5 92 8 hours ago
Last Post: DeaD_EyE
  Question concerning function of a a socket pkm 2 836 May-16-2019, 07:47 PM
Last Post: LavaCreeperKing
  Socket reading script Will86 4 187 Apr-17-2019, 06:57 AM
Last Post: Will86
  Server and Network (socket) [WinError 10053] SheeppOSU 2 158 Apr-13-2019, 09:23 PM
Last Post: SheeppOSU
  Async socket server and ports Pengwyn 1 277 Feb-28-2019, 12:13 AM
Last Post: DeaD_EyE
  Multi connection socket server help! MuntyScruntfundle 0 188 Feb-19-2019, 12:03 PM
Last Post: MuntyScruntfundle
  socket programming (browser) kunz 8 625 Dec-18-2018, 10:13 AM
Last Post: siripriya
  Udp socket rocks88 3 449 Dec-02-2018, 01:26 AM
Last Post: Larz60+
  Multiple network socket servers? MuntyScruntfundle 1 375 Nov-13-2018, 03:46 PM
Last Post: wavic
  Udp broadcast programming project oredri269 0 463 Oct-23-2018, 05:09 PM
Last Post: oredri269

Forum Jump:


Users browsing this thread: 1 Guest(s)