tnetconnect.nim 664 B

1234567891011121314151617181920212223242526272829
  1. discard """
  2. disabled: "i386"
  3. matrix: "-d:ssl"
  4. """
  5. import std/net
  6. from std/strutils import `%`
  7. # bug #15215
  8. proc test() =
  9. let ctx = newContext()
  10. proc fn(url: string) =
  11. let socket = newSocket()
  12. defer: close(socket)
  13. connect(socket, url, Port(443), 5000) # typically 20 could be enough
  14. send(socket, "GET / HTTP/1.0\nHost: $#\nConnection: close\n\n" % [url])
  15. wrapSocket(ctx, socket)
  16. # trying 2 sites makes it more resilent: refs #17458 this could give:
  17. # * Call to 'connect' timed out. [TimeoutError]
  18. # * No route to host [OSError]
  19. try:
  20. fn("www.nim-lang.org")
  21. except TimeoutError, OSError:
  22. fn("www.google.com")
  23. test()