Example explanation 14-WiFi-Shield->tcp_client TCP client
# TCP客户端示例
#
# 此示例显示如何使用WiFi发送和接收TCP通信。
import network, usocket
# AP信息
SSID='' # Network SSID
KEY='' # Network key
# 初始化wlan模块并连接到网络
print("Trying to connect... (may take a while)...")
wlan = network.WINC()
wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK)
# 我们现在通过DHCP应该有一个有效的IP
print(wlan.ifconfig())
# 通过DNS获取地址信息
addr = usocket.getaddrinfo("www.google.com", 80)[0][4]
# 创建一个新的套接字并连接到地址
client = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
client.connect(addr)
# 将超时设置为1秒
client.settimeout(1.0)
# 发送HTTP请求和recv响应
client.send("GET / HTTP/1.0\r\n\r\n")
print(client.recv(1024))
# 关闭套接字
client.close()
Singtown Technology OpenMV official Chinese document function explanation:
Singtown Technology OpenMV official Chinese document function explanation:
Singtown Technology OpenMV official Chinese document function explanation: