[Python] Convert this socket server sketch from python to micro-python

Discussão em 'Python' iniciado por Stack, Dezembro 21, 2024.

  1. Stack

    Stack Membro Participativo

    #Imports modules
    import socket
    import time

    listensocket = socket.socket() #Creates an instance of socket
    Port = 8000 #Port to host server on
    maxConnections = 999
    IP = socket.gethostname() #IP address of local machine

    listensocket.bind(('',Port))

    #Starts server
    listensocket.listen(maxConnections)
    print("Server started at " + IP + " on port " + str(Port))

    #Accepts the incomming connection
    (clientsocket, address) = listensocket.accept()
    print("New connection made!")

    running = True

    while running:
    message = clientsocket.recv(1024).decode() #Gets the incomming message
    print(message)


    This sketch receives text from another computer and works great in python. When I run it in micro-python I get attribute error, object has no attribute 'gethostname'

    I am trying to send text from my pc to ESP32(Cardcomputer). The python sketch I use to send the text works in both python and Micro-python without any modifications or problems.

    Continue reading...

Compartilhe esta Página