Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I getting the error "connection refused" in Python? (Sockets)
    primarykey
    data
    text
    <p>I'm new to Sockets, please excuse my complete lack of understanding. </p> <p>I have a server script(server.py): </p> <pre><code>#!/usr/bin/python import socket #import the socket module s = socket.socket() #Create a socket object host = socket.gethostname() #Get the local machine name port = 12397 # Reserve a port for your service s.bind((host,port)) #Bind to the port s.listen(5) #Wait for the client connection while True: c,addr = s.accept() #Establish a connection with the client print "Got connection from", addr c.send("Thank you for connecting!") c.close() </code></pre> <p>and client script (client.py): </p> <pre><code>#!/usr/bin/python import socket #import socket module s = socket.socket() #create a socket object host = '192.168.1.94' #Host i.p port = 12397 #Reserve a port for your service s.connect((host,port)) print s.recv(1024) s.close </code></pre> <p>I go to my desktop terminal and start the script by typing: </p> <pre><code>python server.py </code></pre> <p>after which, I go to my laptop terminal and start the client script: </p> <pre><code>python client.py </code></pre> <p>but I get the following error: </p> <blockquote> <p>File "client.py", line 9, in </p> <p>s.connect((host,port)) </p> <p>File "/usr/lib/python2.7/socket.py", line 224, in meth</p> <p>return getattr(self._sock,name)(*args)</p> <p>socket.error: [Errno 111] Connection refused</p> </blockquote> <p>I've tried using different port numbers to no avail. However, I was able to get the host name using the same ip and the gethostname() method in the client script and I can ping the desktop (server). </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload