title: ConnectionRefusedError: [Errno 111] Connection refused between laptop and raspberry pi using python
body: <p>I am a beginner in socket communication and I wanted to test this code.</p>
  <p>I wrote the same code but changed the host in the server to s.gethostname() when both the client and server were on my laptop and worked normally.</p>
  <p>server: Laptop</p>
  <pre><code>import socket
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  host = ''
  port = 62402
  s.bind((host,port))
  s.listen(5)
  while True:
    clientsocket, address = s.accept()
    print(f&quot;connection from {address} has been established!&quot;)
    clientsocket.send(bytes(&quot;Welcome to the server!&quot;,&quot;utf-8&quot;))
  </code></pre>
  <p>client: raspberry pi</p>
  <pre><code>import socket
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  host = socket.gethostname()
  port = 62402
  s.connect((host,port))
  msg = s.recv(1024)
  print(msg.decode('utf-8')
  </code></pre>
  <p>Error</p>
  <pre><code>Traceback(most recent call last):
   File &quot;/home/pi/Desktop/testting/client.py&quot;, line 6, in &lt;module&gt;
    s.connect((host,port))
  ConnectionRefusedError: [Error 111] Connection refused
  </code></pre>