Use Socket to connect to the forum

Socket is almost the base of the entire network communication. In this project, we will use Socket to connect to a designated server to obtain its information from the Internet. You can search many servers with telnet protocol on the Internet. By connecting to these servers, you can browse the web and forums, and even read character animation in the terminal!

We will connect to the "freechess.org" forum to get information in the terminal in this example. Enter the following code into the code editor:

import network
import usocket
from machine import Pin, I2C, ADC, UART, SPI, PWM
from time import sleep

N1 = network.WLAN_UART(network.STA_IF)

print("API list:")

print("wifi list:")
lis = N1.scan()
for q in lis:

if N1.isconnected():
    print("    ip               gateway           netmask            MAC            ssid")
    addr_info = usocket.getaddrinfo('freechess.org',5000)
    addr = addr_info[0][-1]
   # addr=('',23)
   # s.send('Hello!')
while True:
    data = s.recv(500)
    print(str(data, 'utf8'), end = '')
Pay attention to replace with your own WiFi name and password on line 17, then run the program and get the result in the Shell window. image.png You can also find other servers that support the telnet protocol on the Internet, and then fill in the server address and port as shown. Now, you can use the terminal to visit these websites! image.png