File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 import socket
55
66
7- s = socket .socket ()
7+ def main (use_stream = False ):
8+ s = socket .socket ()
89
9- ai = socket .getaddrinfo ("google.com" , 80 )
10- print ("Address infos:" , ai )
11- addr = ai [0 ][4 ]
10+ ai = socket .getaddrinfo ("google.com" , 80 )
11+ print ("Address infos:" , ai )
12+ addr = ai [0 ][4 ]
1213
13- print ("Connect address:" , addr )
14- s .connect (addr )
14+ print ("Connect address:" , addr )
15+ s .connect (addr )
1516
16- if 0 :
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 " )
21- print (s .readall ())
22- else :
23- s .send (b"GET / HTTP/1.0\n \n " )
24- print (s .recv (4096 ))
17+ if use_stream :
18+ # MicroPython socket objects support stream (aka file) interface
19+ # directly, but the line below is needed for CPython.
20+ s = s .makefile ("rwb" , 0 )
21+ s .write (b"GET / HTTP/1.0\n \n " )
22+ print (s .readall ())
23+ else :
24+ s .send (b"GET / HTTP/1.0\n \n " )
25+ print (s .recv (4096 ))
26+
27+
28+ main ()
You can’t perform that action at this time.
0 commit comments