1

Please help me; I don't know how to process the packet rate loss in Python from 0-10%.

I need to write the sender.py and receiver.py to connect with the channel and modifiy the channel so it can send the picture.

Here is the code for channel.py:

#
import random
import socket
from socket import *

#Vary the channel loss rate between 0-10
lossRate = 0

#Create UDP sockets for sender and receiver
senderSocket = socket(AF_INET, SOCK_DGRAM)
receiverSocket = socket(AF_INET, SOCK_DGRAM)

# Assign IP address and port numbers to 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 the messages from sender 
    senderMessage, senderAddress = senderSocket.recvfrom(1600)

    #forward the frame to the receiver with a random loss
    rand = random.randint(0,99)
    if rand > lossRate:
        receiverSocket.sendto(senderMessage, receiverAddress)
    #receive the ACK from receiver         
        receiverMessage, receiverAddress = receiverSocket.recvfrom(1600)    

        #forward the ACK to the sender with a random loss   
        rand = random.randint(0,99)
        if rand > lossRate:    
            senderSocket.sendto(receiverMessage, senderAddress)    
Unheilig
  • 16,196
  • 193
  • 68
  • 98
Mina Dolly
  • 11
  • 2
  • Show your code please. – Martze Apr 23 '15 at 06:18
  • Is your goal to implement some kind of file transfer protocol over UDP and control the packet loss to see how packet loss affects the resulting image? – James Mills Apr 23 '15 at 06:21
  • I try to write the sender.py and receiver.py to process the image through channel.py and run them in terminal. Then time the process to see how long it take in ms. This has to do with stop and wait protocol. – Mina Dolly Apr 23 '15 at 23:35

0 Answers0