[英]Python socket errno 32 broken pipe
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"我正在尝试通过 python 通过 TCP/IP 发送一条消息,第一条消息已收到,但是当我尝试发送另一条消息时它返回:“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?
有人对此有解决方案吗?
maybe SIGPIPE error :也许是 SIGPIPE错误:
Your server process has received a SIGPIPE writing to a socket.
您的服务器进程已收到写入套接字的 SIGPIPE。 This usually happens when you write to a socket fully closed on the other (client) side.
当您写入在另一端(客户端)完全关闭的套接字时,通常会发生这种情况。 This might be happening when a client program doesn't wait till all the data from the server is received and simply closes a socket (using close function).
当客户端程序不等到从服务器接收到所有数据并简单地关闭套接字(使用关闭函数)时,可能会发生这种情况。
In a C program you would normally try setting to ignore SIGPIPE signal or setting a dummy signal handler for it.
在 C 程序中,您通常会尝试设置忽略 SIGPIPE 信号或为其设置虚拟信号处理程序。 In this case a simple error will be returned when writing to a closed socket.
在这种情况下,写入关闭的套接字时将返回一个简单的错误。 In your case a python seems to throw an exception that can be handled as a premature disconnect of the client.
在您的情况下,python 似乎抛出了一个异常,可以作为客户端过早断开连接来处理。
How to prevent errno 32 broken pipe? 如何防止errno 32 断管?
How to handle a broken pipe (SIGPIPE) in python? 如何在 python 中处理损坏的管道(SIGPIPE)?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.