File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ try :
2+ import usocket as _socket
3+ except :
4+ import _socket
5+ try :
6+ import ussl as ssl
7+ except :
8+ import ssl
9+
10+
11+ def main (use_stream = True ):
12+ s = _socket .socket ()
13+
14+ ai = _socket .getaddrinfo ("google.com" , 443 )
15+ print ("Address infos:" , ai )
16+ addr = ai [0 ][4 ]
17+
18+ print ("Connect address:" , addr )
19+ s .connect (addr )
20+
21+ s = ssl .wrap_socket (s )
22+ print (s )
23+
24+ if use_stream :
25+ # Both CPython and MicroPython SSLSocket objects support read() and
26+ # write() methods.
27+ s .write (b"GET / HTTP/1.0\n \n " )
28+ print (s .read (4096 ))
29+ else :
30+ # MicroPython SSLSocket objects implement only stream interface, not
31+ # socket interface
32+ s .send (b"GET / HTTP/1.0\n \n " )
33+ print (s .recv (4096 ))
34+
35+
36+ main ()
You can’t perform that action at this time.
0 commit comments