Home > other >  RTL8722 MicroPython Socket - the Echo server and the client
RTL8722 MicroPython Socket - the Echo server and the client

Time:05-06

The simplest is to use the WiFi network communication Socket for point-to-point communication, want to know your build Server and client to have the correct operation, you will find the two can use WiFi devices, let the interconnection between them and the echo () response to the same information do validation information to each other, the following is the overhand,

materials prepared
RTL8722 x 2
Examples
WiFi connection can be used after the completion of the Socket to use the Internet, the Socket as a hypothetical Ethernet interface, you can use it to connect your PC to Internet servers, such as Google or a lot, even if the application layer protocol such as HTTP is built on the Socket, once a given IP address and port number, you can freely communicate with connection to the remote device, connection process as shown in the figure below,



The following is a server socket and the client socket sample to deliver the message, you want to use this example, you need two RTL8722 to run MicroPython, copy and paste in REPL mode respectively will copy and paste the following code into two RTL8722,

Below is the server code
 
The import socket
The from wireless import WLAN
Wifi=WLAN (mode=WLAN. The STA)
Wifi. Connect (ssid="YourWiFiSSID", PSWD="YourWiFiPassword") # change the ssid and PSWD to yours
S=socket. The SOCK ()
Port=5000
S.b ind (port)
S.l isten ()
Conn, addr=s.a ccept ()
While True:
Data=https://bbs.csdn.net/topics/conn.recv (1024)
Conn. Send (data + "from the server")


Below is the client code

 
The import socket
The from wireless import WLAN
Wifi=WLAN (mode=WLAN. The STA)
Wifi. Connect (ssid="YourWiFiSSID", PSWD="YourWiFiPassword") # change the ssid and PSWD to yours
C=socket. The SOCK ()
# make sure to check the server IP address and update in the next line of code
Arthur c. onnect (" your server IP address ", 5000)
C.s. end (" hello world ")
Data=https://bbs.csdn.net/topics/c.recv (1024)
Print (data)
  • Related