[Python] Python socket errno 32 broken pipe

Discussão em 'Python' iniciado por Stack, Junho 4, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to send a message over TCP/IP via python, the first message has been received but when I try to send another one it returns: "socket error32 broken pipe"

    my code:

    import socket
    from RPi import GPIO
    from time import sleep

    TCP_IP = '192.168.178.29'
    TCP_PORT = 45335
    BUFFER_SIZE = 1024
    MESSAGE = "Hello, World!"

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((TCP_IP, TCP_PORT))

    clk = 17
    dt = 18

    GPIO.setmode(GPIO.BCM)
    GPIO.setup(clk, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    GPIO.setup(dt, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

    counter = 0
    clkLastState = GPIO.input(clk)

    try:
    while True:
    clkState = GPIO.input(clk)
    dtState = GPIO.input(dt)
    if clkState != clkLastState:
    if dtState != clkState:
    counter += 1
    else:
    counter -= 1
    s.send(str(counter))
    print counter
    clkLastState = clkState
    sleep(0.01)
    finally:
    GPIO.cleanup()


    I tried searching for this issue but I couldn't find a solution, the socket is still open when I try to send the second message. Does anyone have a solution for this?

    Continue reading...

Compartilhe esta Página