Python Forum
Splitting the audio file into smaller packets before transfer using UDP protocol in p
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Splitting the audio file into smaller packets before transfer using UDP protocol in p
#1
I am required to send an audio file form client to server using UDP protocol (python) in packets of 500 bytes each. Then problem statement for sender is given as: "The sender should run as follows: The sender will read the file specified by the filename and transfer it using UDP sockets. On completing the transfer, the sender should terminate and exit. The sender should bind to listen port to receive acknowledgments and other signaling from the receiver. You should only use a single UDP socket for both sending and receiving data. Note that although UDP will allow you to send large packets using IP fragmentation, but make sure that you restrict your packets to 500 bytes (in payload). " The problem statement for receiver is given as: "The receiver should run as follows: The receiver will need to bind to the UDP port specified on the command line and receive a file from the sender sent over the port. The file should be saved to a different filename. Note that you should make sure in your testing that the filename used by the receiver is not the same as the one used by the sender. The receiver should exit once the transfer is complete."

THE CLIENT THAT IS SENDER CODE IS GIVEN BELOW

from socket import *
    import time

    # Assigning server IP and server port
    serverName = "127.0.0.1"
    serverPort = 5000
    # Setting buffer length
    buffer_length = 500
    # Assigning the audio file a name
    my_audio_file = r"C:\Users\mali.bee17seecs\PycharmProjects\TestProject\Aye_Rah-e-Haq_Ke_Shaheedo.mp3"
    clientSocket = socket(AF_INET, SOCK_DGRAM)
    # Opening the audio file
    f = open(my_audio_file, "rb")
    # Reading the buffer length in data
    data = f.read(buffer_length)

    # While loop for the transfer of file
    while data:
        if clientSocket.sendto(data, (serverName, serverPort)):
            data = f.read(buffer_length)
            time.sleep(0.02)  # waiting for 0.02 seconds
    clientSocket.close()
    f.close()
    print("File has been Transferred")
THE SERVER THAT IS RECEIVER CODE IS GIVEN BELOW

from socket import *
import select
# Assigning server IP and server port
serverName = "127.0.0.1"
serverPort = 5000
# Setting timeout
timeout = 3
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind((serverName, serverPort))
# While loop for the receiving of file
while True:
    data, serverAddress = serverSocket.recvfrom(1024)
    if data:
        file = open(r"C:\Users\mali.bee17seecs\PycharmProjects\TestProject\Aye_Rah-e-Haq_Ke_Shaheedo.mp3",
                 "wb")
        while True:
            ready = select.select([serverSocket], [], [], timeout)
            if ready[0]:
                data, serverAddress = serverSocket.recvfrom(500)
                file.write(data)
            else:
                file.close()
                print("File has been Received")
                break
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  chua osillator to audio file sddfds 0 430 Jul-13-2023, 11:07 PM
Last Post: sddfds
  splitting file into multiple files by searching for string AlphaInc 2 877 Jul-01-2023, 10:35 PM
Last Post: Pedroski55
  Splitting vocals from .wav file cfescript 1 622 May-15-2023, 09:28 PM
Last Post: Calab
  file transfer via python SFTP SCP mg24 3 2,965 Sep-15-2022, 04:20 AM
Last Post: mg24
  Multithreaded file transfer from multiple volumes skoobi 2 1,138 Jul-28-2022, 07:52 AM
Last Post: skoobi
  I have an issue with Netmiko Error reading SSH protocol banner omarhegazy 2 3,561 May-16-2022, 06:05 PM
Last Post: omarhegazy
  Programming a routing protocol leemao 2 2,173 Jul-13-2021, 05:47 PM
Last Post: leemao
Question resume file transfer onran 0 1,629 Jan-27-2021, 02:16 PM
Last Post: onran
  Remote File Transfer- Error wonderboy 1 1,665 Jan-06-2021, 11:24 AM
Last Post: wonderboy
  splitting UAV/sat images to smaller pieces in order to feed a CNN hobbyist 0 1,524 Dec-08-2020, 11:48 AM
Last Post: hobbyist

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020