Skip to main content

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_SPI(network.STA_IF)
N1.active(True)

print("API list:")
dir(N1)

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

N1.connect("CHCK","depot0510")
if N1.isconnected():
print(" ip gateway netmask MAC ssid")
print(N1.ifconfig())
addr_info = usocket.getaddrinfo('freechess.org',5000)
print(addr_info)
addr = addr_info[0][-1]
print(addr)
s=usocket.socket()
# addr=('171.160.169.200',23)
s.connect(addr)
# 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

Tech Support & Product Discussion‚Äč

if you have any technical issue. submit the issue into our forum. Thank you for choosing our products! We are here to provide you with different support to ensure that your experience with our products is as smooth as possible. We offer several communication channels to cater to different preferences and needs.

Loading Comments...