Format: text/x-python
⬇ Download File (922 B)
   1  # Copyright (c) Microsoft Corporation. All rights reserved.
   2  # Licensed under the MIT License. See LICENSE in the project root
   3  # for license information.
   4  
   5  __all__ = []
   6  
   7  
   8  adapter_host = None
   9  """The host on which adapter is running and listening for incoming connections
  10  from the launcher and the servers."""
  11  
  12  channel = None
  13  """DAP message channel to the adapter."""
  14  
  15  
  16  def connect(host, port):
  17      from debugpy.common import log, messaging, sockets
  18      from debugpy.launcher import handlers
  19  
  20      global channel, adapter_host
  21      assert channel is None
  22      assert adapter_host is None
  23  
  24      log.info("Connecting to adapter at {0}:{1}", host, port)
  25  
  26      sock = sockets.create_client()
  27      sock.connect((host, port))
  28      adapter_host = host
  29  
  30      stream = messaging.JsonIOStream.from_socket(sock, "Adapter")
  31      channel = messaging.JsonMessageChannel(stream, handlers=handlers)
  32      channel.start()
  33