title: socket connection refused: telnet: Unable to connect to remote host: Connection refused
body: <p>I have been teaching myself python sockets module with the help of <em>sentdex</em>. When i attempted to run the code the were no errors. The code was:</p>
  
  <pre><code>`import socket
  from _thread import *
  
  host = 'localhost'
  port = 5555
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  
  try:
      s.bind((host, port))
  except socket.error as e:
      print(str(e))
  
  s.listen(5)
  print('Waiting for a connection.')
  def threaded_client(conn):
      conn.send(str.encode('Welcome, type your info\n'))
  
      while True:
          data = conn.recv(2048)
          reply = 'Server output: '+ data.decode('utf-8')
          if not data:
              break
          conn.sendall(str.encode(reply))
      conn.close()
  
  
  while True:
  
      conn, addr = s.accept()
      print('connected to: '+addr[0]+':'+str(addr[1]))
  
      start_new_thread(threaded_client,(conn,))
  `
  </code></pre>
  
  <p>When I attempted to connect to it on my raspberry pi, it gave the error:
  <code>telnet: Unable to connect to remote host: Connection refused</code>
  I tried modifying the host to a myriad of different options that I read in other question such as <code>host=''</code>, <code>host=127.0.0.1</code>, and <code>host=0.0.0.0</code>. All to no avail;however, it did make a connection when I tried <code>host='localhost'</code> on the computer running the script. When i attempted to ping it from my raspberry pi 3, it did nothing. At first, it appeared to be working, but after a while of no change, when I canceled it, the raspberry pi showed that no packages have been received. Please tell me what could be the problem. Could it be either syntactical or firewall-based?</p>