
UiFlow 使用教程
创建 UDP Server 监听数据接收, 并发送返回相同的数据内容。通过网络相关的 API 可获取当前本机的 IP 地址, 用于提供其他 Client 数据发送。
from m5stack import *
from m5ui import *
from uiflow import *
import network
import socket
setScreenColor(0x222222)
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('SSID', 'PASSWORD')
print(wlan.ifconfig())
udpsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udpsocket.bind(('0.0.0.0', 5000))
while True:
print(udpsocket.recv(1024))
wait_ms(2) udpsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udpsocket.bind(('0.0.0.0', 5000)) udpsocket.sendto('Hello', ('192.168.31.11', 5000)) udpsocket.close() data = udpsocket.recv(1024) data = udpsocket.read(10) 创建 UDP Client 发送数据到指定服务器。
from m5stack import *
from m5ui import *
from uiflow import *
import socket
import time
setScreenColor(0x222222)
udpsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udpsocket.connect(('192.168.31.10', 5000))
while True:
udpsocket.send('Hello World')
wait(1)
wait_ms(2) udpsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udpsocket.connect(('192.168.31.10', 5000)) udpsocket.send('Hello World') udpsocket.write('') udpsocket.sendto('Hello World', ('192.168.31.10', 5000)) udpsocket.close() data = udpsocket.recv(1024) data = udpsocket.read(10)