2014-01-20 13:35:18 -05:00
|
|
|
try:
|
2014-10-09 13:43:10 -04:00
|
|
|
import usocket as _socket
|
2014-01-20 13:35:18 -05:00
|
|
|
except:
|
|
|
|
import _socket
|
|
|
|
|
|
|
|
|
|
|
|
s = _socket.socket()
|
2014-01-18 16:49:06 -05:00
|
|
|
|
2016-04-01 13:58:12 -04:00
|
|
|
ai = _socket.getaddrinfo("google.com", 80)
|
|
|
|
print("Address infos:", ai)
|
|
|
|
addr = ai[0][4]
|
2014-01-18 16:49:06 -05:00
|
|
|
|
|
|
|
print("Connect address:", addr)
|
|
|
|
s.connect(addr)
|
|
|
|
|
2014-01-20 13:35:18 -05:00
|
|
|
if 0:
|
|
|
|
# MicroPython rawsocket module supports file interface directly
|
|
|
|
s.write("GET / HTTP/1.0\n\n")
|
|
|
|
print(s.readall())
|
|
|
|
else:
|
|
|
|
s.send(b"GET / HTTP/1.0\n\n")
|
|
|
|
print(s.recv(4096))
|