code: def main(argv=sys.argv[1:], loop=None):
      
      args = docopt(__doc__, argv=argv,
                    version=pkg_resources.require('rflink')[0].version)
  
      level = logging.ERROR
      if args['-v']:
          level = logging.INFO
      if args['-v'] == 2:
          level = logging.DEBUG
      logging.basicConfig(level=level)
  
      if not loop:
          loop = asyncio.get_event_loop()
  
      host = args['--host']
      port = args['--port']
      baud = args['--baud']
      listenport = args['--listenport']
  
      proxy = RFLinkProxy(port=port, host=host, baud=baud, loop=loop)
  
      server_coro = asyncio.start_server(
          proxy.client_connected_callback,
          host="",
          port=listenport,
          loop=loop,
      )
  
      server = loop.run_until_complete(server_coro)
      addr = server.sockets[0].getsockname()
      log.info('Serving on %s', addr)
  
      conn_coro = proxy.connect()
      loop.run_until_complete(conn_coro)
  
      proxy.closing = False
      try:
          loop.run_forever()
      except KeyboardInterrupt:
          proxy.closing = True
  
          # cleanup server
          server.close()
          loop.run_until_complete(server.wait_closed())
  
          # cleanup server connections
          writers = [i[1] for i in list(clients)]
          for writer in writers:
              writer.close()
              if sys.version_info >= (3, 7):
                  loop.run_until_complete(writer.wait_closed())
  
          # cleanup RFLink connection
          proxy.transport.close()
  
      finally:
          loop.close()
docs: Parse argument and setup main program loop.