[Python] Create a Python Bluetooth audio streaming server on Windows 10

Discussão em 'Python' iniciado por Stack, Abril 10, 2025.

  1. Stack

    Stack Membro Participativo

    Ok either I'm losing my mind or Windows is doing something else. I want to create a Bluetooth server within Python that users, on their phones, may connect to and stream audio, but when I run it my computer is not visible from any device. I don't want to make it available using the default Windows settings, as then the Windows will take control over the interaction.

    import socket

    HOST_MAC_ADDR = "38:fc:98:6e:2a:bb" # wtvr ur Bluetooth MAC address is
    PORT = 3

    server = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
    server.bind((HOST_MAC_ADDR, PORT))
    server.listen(10)

    print("Waiting for connections")

    try:
    client, address = server.accept()
    print(f"Connected to {address}")

    while True:
    data = client.recv(1024)

    if not data:
    break

    print(f"Recieved: {data.decode("utf-8")}")
    client.send(data)

    except KeyboardInterrupt:
    print("Closing time.")

    finally:
    client.close()
    server.close()


    So when I tried to make Windows show my device, Windows took control over Bluetooth and not my python script.

    When I tried to run the program only the first line is visible in the output, and the computer is not visible from my phone.

    What might be something I should do or rewrite to achieve a proper Bluetooth server using Sockets and Python.

    TLDR: Code not working properly, I have no idea why. Bluetooth is funny.

    Continue reading...

Compartilhe esta Página