blob: 548756bbf4648d88aae223db10f0c01020eae9e7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
try:
import usocket as socket
except:
import socket
s = socket.socket()
ai = socket.getaddrinfo("google.com", 80)
print("Address infos:", ai)
addr = ai[0][4]
print("Connect address:", addr)
s.connect(addr)
if 0:
# MicroPython socket objects support stream (aka file) interface
# directly, but the line below is needed for CPython.
s = s.makefile("rwb", 0)
s.write(b"GET / HTTP/1.0\n\n")
print(s.readall())
else:
s.send(b"GET / HTTP/1.0\n\n")
print(s.recv(4096))
|