Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8654655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:50:29+00:00 2026-06-12T14:50:29+00:00

I am sending file using python’ UDP socket. At receiver side(file_receiver.py), you need to

  • 0

I am sending file using python’ UDP socket. At receiver side(file_receiver.py), you need to interrupt (ctrl-c) the program in order to receive the file at the end. Therefore I put settimeout for 2 second, to program to quit automatically, once data is received completely. If I know well, you can not set non-blocking socket in UDP. what is the best way to overcome this problem.

file_sender.py

#!/usr/bin/env python

from socket import *
import sys

s = socket(AF_INET,SOCK_DGRAM)
host ="localhost"
port = 9999
buf =1024
addr = (host,port)

f=open (sys.argv[1], "rb") 
data = f.read(buf)
while (data):
    if(s.sendto(data,addr)):
        print "sending ..."
        data = f.read(buf)
s.close()
f.close()

file_receiver.py

#!/usr/bin/env python

from socket import *
import sys
import select

host="0.0.0.0"
port = 9999
s = socket(AF_INET,SOCK_DGRAM)
s.bind((host,port))

addr = (host,port)
buf=1024


f = open("op.pdf",'wb')
data,addr = s.recvfrom(buf)


while(data):
    f.write(data)
    s.settimeout(2)
    data,addr = s.recvfrom(buf)

f.close()
s.close()

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:50:30+00:00Added an answer on June 12, 2026 at 2:50 pm

    Because UDP is connection-less, there’s no straight-forward way for the receiving side to know when the sender is done.

    You could work around this, for example, by sending a special packet when the sender is done that indicates that no more packets will follow.

    However, I would strongly advise you against that; UDP doesn’t make guarantees about delivery of packets—packets may be lost, duplicated or delivered out of order. Clearly, for most files it would be unacceptable if they were missing a part, or where reordered, etc.. If you want to transfer a file between to hosts, I think you’re much better off using TCP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a secure transfer file program using Python and AES and
I'm writing a simple program in Python 2.7 using pycURL library to submit file
I am using this for sending file to user header('Content-type: application/zip'); header('Content-Length: ' .
I'm sending a ms-word file using rails. i.e when I click on a link,
I am reading a very large file using a NSInputStream and sending them to
I am sending an audio file with extension .m4a on the server using ftp
I'm sending a file using the response << file.newInputStream (similar to this answer here
I am sending file using following code in my android application : Intent intent
my application sends file to server using (socket tcp c#) the file transfer works
I am sending a fix message over socket connection and recieving within a python

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.