Hello, I have a problem connecting to the server. The problem is with the bind() method, which somehow does not work as it should. Could you please help me?
import network
import socket
SSID = 'TEST'
PASSWORD = 'test123'
HOST = '0.0.0.0'
PORT = 80
wlan = network.WLAN_SPI(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)
while not wlan.isconnected():
pass
print('connected to the network', SSID)
print('IP adress:', wlan.ifconfig()[0])
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
print('The port is', PORT)
while True:
conn, addr = s.accept()
print('Pripojenie od', addr)
request = conn.recv(1024)
response = 'HTTP/1.1 200 OK\nContent-Type: text/html\n\n'
response += '<html><body><h1>A simple WIORP2040 server</h1></body></html>'
conn.send(response)
conn.close()
The goal of this code is to throw out the IP address to which I connect via a web browser.
Current error:
Traceback (most recent call last):
File “”, line 20, in
AttributeError: ‘socket’ object has no attribute ‘bind’