code: def watch(callback, url=default_sock_url):
      
      sock, hostname = connect(url)
      request = 'GET /events HTTP/1.1\nHost: %s\n\n' % hostname
      request = request.encode('utf-8')
  
      with closing(sock):
          sock.sendall(request)
          header, payload = read_http_header(sock)
          status, reason = header_status(header)
          if status != HTTP_OK:
              raise DockermonError('bad HTTP status: %s %s' % (status, reason))
  
          # Messages are \r\n<size in hex><JSON payload>\r\n
          buf = [payload]
          while True:
              chunk = sock.recv(bufsize)
              if not chunk:
                  raise EOFError('socket closed')
              buf.append(chunk.decode('utf-8'))
              data = ''.join(buf)
              i = data.find('\r\n')
              if i == -1:
                  continue
  
              size = int(data[:i], 16)
              start = i + 2  # Skip initial \r\n
  
              if len(data) < start + size + 2:
                  continue
              payload = data[start:start+size]
              callback(json.loads(payload))
              buf = [data[start+size+2:]]
docs: Watch docker events. Will call callback with each new event (dict).
  
          url can be either tcp://<host>:port or ipc://<path>