title: Python: Socket.error Connection Refused in Unix [Errno 111]
body: <p>I am trying to send UDP video packets using sockets in Python. </p>
  
  <p>The Server IP address is :192.168.67.14</p>
  
  <p>The Client IP address is 192.168.67.42</p>
  
  <p>The Client and Server can ping each other. Below is the code used for establishing the socket:</p>
  
  <p>Server Side:</p>
  
  <pre><code>import urllib, time, os, m3u8
  from socket import *
  
  # Socket initialization
  
  s = socket(AF_INET, SOCK_DGRAM)
  host = "192.168.67.42"
  port = 5000
  buf = 1024
  addr = (host, port)
  s.connect((host, port))
  
  ts_filenames = []
  while True:
      playlist = "https://sevenwestmedia01-i.akamaihd.net/hls/live/224853/TEST1/master_lowl.m3u8"
      m3u8_obj = m3u8.load(playlist)
      ts_segments = m3u8_obj.__dict__.values()[6]
      ts_segments_str = str(m3u8_obj.segments)
      for line in ts_segments_str.splitlines():
          if "https://" in line:
              ts_id = line[-20:]
              if ts_id not in ts_filenames:
                  print ts_id
                  ts_filenames.append(ts_id)
                  try:
                      ts_segment = urllib.URLopener()
                      ts_segment.retrieve(line, ts_id)
                  except:
                      pass
                  f = open(ts_id, "rb")
                  data = f.read(buf)
                  while (data):
                      if (s.sendto(data, addr)):
                          print "sending ..."
                          data = f.read(buf)
  </code></pre>
  
  <p>Client Side</p>
  
  <pre><code>import socket 
  
  s = socket.socket() 
  host = '192.168.67.14' 
  port = 5000 
  
  s.connect((host,port))
  print s.recv(1024)
  s.close
  </code></pre>
  
  <p>Exception I get:</p>
  
  <blockquote>
    <p>Traceback (most recent call last):   File "client.py", line 7, in
    
        s.connect((host,port))   File "/usr/lib/python2.7/socket.py", line 228, in meth
        return getattr(self._sock,name)(*args) socket.error: [Errno 111] Connection refused</p>
  </blockquote>
  
  <p>I spent some time looking into <a href="https://stackoverflow.com/questions/16130786/why-am-i-getting-the-error-connection-refused-in-python-sockets">this discussion</a> but I still not sure what to modify. Any suggestions please ?</p>