python udp socket远程主机强迫关闭_远程主机(简单UDP客户端服务器)强制关闭了现有连接...

这里绝对是新手,我似乎找不到问题的答案。运行Python2.7。在

我的服务器代码如下:#UDPPingerClient.py

from socket import *

#Create a UDP socket

clientSocket = socket(AF_INET, SOCK_DGRAM)

#Assign IP address and port number to socket

clientSocket.bind(("127.0.0.1",9501))

#Set a timeout value of 1 second

clientSocket.settimeout(1)

msg = "test"

#the server info

sIP = "127.0.0.1"

sPort = 12007

addr = (sIP,sPort)

a = 10

# the server will automatically drop some messages

# so we send 10 to make sure it gets there and then

# listen for a response from the server

while a > 0:

clientSocket.sendto(msg,addr)

try:

received, server = clientSocket.recvfrom(1024)

print received

except timeout:

print ('an error occured

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值