__init__.py 925 B

123456789101112131415161718192021222324252627282930313233
  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. __all__ = []
  5. adapter_host = None
  6. """The host on which adapter is running and listening for incoming connections
  7. from the launcher and the servers."""
  8. channel = None
  9. """DAP message channel to the adapter."""
  10. def connect(host, port):
  11. from debugpy.common import log, messaging, sockets
  12. from debugpy.launcher import handlers
  13. global channel, adapter_host
  14. assert channel is None
  15. assert adapter_host is None
  16. log.info("Connecting to adapter at {0}:{1}", host, port)
  17. ipv6 = host.count(":") > 1
  18. sock = sockets.create_client(ipv6)
  19. sock.connect((host, port))
  20. adapter_host = host
  21. stream = messaging.JsonIOStream.from_socket(sock, "Adapter")
  22. channel = messaging.JsonMessageChannel(stream, handlers=handlers)
  23. channel.start()