python - UDP file transfer with channel -
please me; don't know how process packet rate loss in python 0-10%.
i need write sender.py , receiver.py connect channel , modifiy channel can send picture.
here code channel.py:
# import random import socket socket import * #vary channel loss rate between 0-10 lossrate = 0 #create udp sockets sender , receiver sendersocket = socket(af_inet, sock_dgram) receiversocket = socket(af_inet, sock_dgram) # assign ip address , port numbers sockets sendersocket.bind(('127.0.0.1', 5001)) receiversocket.bind(('127.0.0.1', 5002)) receivermessage, receiveraddress = receiversocket.recvfrom(1600) print "receiver ready" while true: # receive messages sender sendermessage, senderaddress = sendersocket.recvfrom(1600) #forward frame receiver random loss rand = random.randint(0,99) if rand > lossrate: receiversocket.sendto(sendermessage, receiveraddress) #receive ack receiver receivermessage, receiveraddress = receiversocket.recvfrom(1600) #forward ack sender random loss rand = random.randint(0,99) if rand > lossrate: sendersocket.sendto(receivermessage, senderaddress)