socket.error: [Errno 32] Broken pipe错误的原因
linux下的socket程序,尝试发送消息到已关闭的socket上,会出现此错误.
示例代码
服务端server.py
#encoding=utf-8 import socket import time def main(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(('0.0.0.0', 8050)) sock.listen(5) client_sock, address = sock.accept() while True: msg = client_sock.recv(1024) print msg client_sock.send('from server: %s' % msg) time.sleep(1) client_sock.close() sock.close() if __name__ == '__main__': main()
客户端client.py
#encoding=utf-8 import socket import time def main(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(('0.0.0.0', 8050)) while True: sock.send('hi') print sock.recv(1024) time.sleep(1) sock.close() if __name__ == '__main__': main()
运行server.py和client.py,然后中断client.py会出现上面错误。
2021年1月05日 16:05
Merely a smiling visitant here to share the love (:, btw outstanding style. movies 123
2023年7月23日 05:57
Your blog provided us with valuable information to work with. Thanks a lot for sharing. I am from Imamia Quran Academy. Online Shia Quran Center provides you Shia Quranic education by the best scholars. Also, authentic Shia Quran translation and Shia Quran commentary are available for online users. Online users will be provided with the authentic experience of a regular Shia Quran Center without being physically present in certain premises.
2023年12月07日 15:56
Indeks berita terkini dan terbaru hari ini dari peristiwa, kecelakaan, kriminal, hukum, berita unik, Politik, dan liputan khusus di Indonesia dan Internasional.