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 9270167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:18:11+00:00 2026-06-18T15:18:11+00:00

I found the code here: Send a file through sockets in Python (the selected

  • 0

I found the code here: Send a file through sockets in Python (the selected answer)

But I will jut post it here again..

server.py
import socket
import sys
s = socket.socket()
s.bind(("localhost",9999))
s.listen(10) 
while True:
    sc, address = s.accept()

    print address
    i=1
    f = open('file_'+ str(i)+".txt",'wb') #open in binary
    i=i+1
    while (True):       
        l = sc.recv(1024)
        while (l):
            print l #<--- i can see the data here
            f.write(l) #<--- here is the issue.. the file is blank
            l = sc.recv(1024)
    f.close()

    sc.close()

s.close()



client.py

import socket
import sys

s = socket.socket()
s.connect(("localhost",9999))
f=open ("test.txt", "rb") 
l = f.read(1024)
while (l):
    print l
    s.send(l)
    l = f.read(1024)
s.close()

On server code, the print l line prints the file contents..so that means that content is being transferred..
but then the file is empty??

what am i missing?
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-18T15:18:12+00:00Added an answer on June 18, 2026 at 3:18 pm

    You are probably trying to inspect the file while the program is running. The file is being buffered, so you likely won’t see any output in it until the f.close() line is executed, or until a large amount of data is written. Add a call to f.flush() after the f.write(l) line to see output in real time. Note that it will hurt performance somewhat.

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

Sidebar

Related Questions

So I have found here in stackoverflow One code for sending through sockets a
I found this code from here: http://www.cssportal.com/form-elements/text-box.htm But the problem is you can still
I am attempting to use the code found in the answer here: Directory.Move doesn't
I found a little script that will export information to an xls file, but
I found this code here class Usable; class Usable_lock { friend class Usable; private:
I am trying to get the code found here: http://snipplr.com/view/26643/mbprogresshud-with-an-asynchronous-nsurlconnection-call/ to work in my
I'm using the javascript ticker code found here . In Chrome and Safari, the
Basically my problem is that i've adapted a piece of code found here http://social.msdn.microsoft.com/Forums/en-US/vemapcontroldev/thread/62e70670-f306-4bb7-8684-549979af91c1
I am trying to install MySQLdb package. I found the source code here .
I've been here and accordingly found out that this piece of code here var

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.