python 网络编程 socket 报错 ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。
生活随笔
收集整理的這篇文章主要介紹了
python 网络编程 socket 报错 ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
服務(wù)端:
# -*- coding: utf-8 -*- """ @File : 191226_基于UDP協(xié)議的socket_server端.py @Time : 2019/12/26 23:32 @Author : Dontla @Email : sxana@qq.com @Software: PyCharm """ import socketip_port = ('127.0.0.1', 9000) BUFSIZE = 1024 udp_server_client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)udp_server_client.bind(ip_port)while True:msg, addr = udp_server_client.recvfrom(BUFSIZE)print(msg, addr)udp_server_client.sendto(msg.upper(), addr)客戶端:
# -*- coding: utf-8 -*- """ @File : 191226_基于UDP協(xié)議的socket_client端.py @Time : 2019/12/26 23:32 @Author : Dontla @Email : sxana@qq.com @Software: PyCharm """import socket import timeip_port = ('127.0.0.1', 9000) BUFSIZE = 1024 udp_server_client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)while True:msg = input('>>: ').strip()if not msg:continueudp_server_client.sendto(msg.encode('utf-8'), ip_port)back_msg, addr = udp_server_client.recvfrom(BUFSIZE)print(back_msg.decode('utf-8'), addr)但是運行后報錯:
D:\20191031_tensorflow_yolov3\python\python.exe D:/20191221_network_programming/network_programming/基于UDP協(xié)議的socket/191226_基于UDP協(xié)議的socket_client端.py >>: a Traceback (most recent call last):File "D:/20191221_network_programming/network_programming/基于UDP協(xié)議的socket/191226_基于UDP協(xié)議的socket_client端.py", line 24, in <module>back_msg, addr = udp_server_client.recvfrom(BUFSIZE) ConnectionResetError: [WinError 10054] 遠(yuǎn)程主機強迫關(guān)閉了一個現(xiàn)有的連接。Process finished with exit code 1原因:
服務(wù)端綁定的ip與主機ip對應(yīng)不上,改成真實的ip地址就好了:
總結(jié)
以上是生活随笔為你收集整理的python 网络编程 socket 报错 ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Brainburn movies
- 下一篇: pycharm 无法更新代码 updat