File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change 11try :
2- import usocket as _socket
2+ import usocket as socket
33except :
4- import _socket
4+ import socket
55
66
7- s = _socket .socket ()
7+ s = socket .socket ()
88
9- ai = _socket .getaddrinfo ("google.com" , 80 )
9+ ai = socket .getaddrinfo ("google.com" , 80 )
1010print ("Address infos:" , ai )
1111addr = ai [0 ][4 ]
1212
1313print ("Connect address:" , addr )
1414s .connect (addr )
1515
1616if 0 :
17- # MicroPython rawsocket module supports file interface directly
18- s .write ("GET / HTTP/1.0\n \n " )
17+ # MicroPython socket objects support stream (aka file) interface
18+ # directly, but the line below is needed for CPython.
19+ s = s .makefile ("rwb" , 0 )
20+ s .write (b"GET / HTTP/1.0\n \n " )
1921 print (s .readall ())
2022else :
2123 s .send (b"GET / HTTP/1.0\n \n " )
You can’t perform that action at this time.
0 commit comments