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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:47:48+00:00 2026-06-13T00:47:48+00:00

I write client-server application like this: client(c#) <-> server (twisted; ftp proxy and additional

  • 0

I write client-server application like this:
client(c#) <-> server (twisted; ftp proxy and additional functional) <-> ftp server

Server has two classes: my own class-protocol inherited from LineReceiever protocol and FTPClient from twisted.protocols.ftp.

But when client sends or gets big files (10 Gb – 20 Gb) server catches MemoryError. I don’t use any buffers in my code. It happens when after call transport.write(data) data appends to inner buffer of reactor’s writers (correct me if I wrong).

What should I use to avoid this problem? Or should I change approach to the problem?

I found out that for big streams, I should use IConsumer and IProducer interfaces. But finally it will invoke transfer.write method and effect will be the same. Or am I wrong?

UPD:

Here is logic of file download/upload (from ftp through Twisted server to client on Windows):

Client sends some headers to Twisted server and after that begins send of file. Twisted server receive headers and after that (if it needs) invoke setRawMode(), open ftp connection and recieves/sends bytes from/to client and after all close connections. Here is a part of code that uploads files:

FTPManager class

def _ftpCWDSuccees(self, protocol, fileName):
        self._ftpClientAsync.retrieveFile(fileName, FileReceiver(protocol))



class FileReceiver(Protocol):
    def __init__(self, proto):
        self.__proto = proto

    def dataReceived(self, data):
        self.__proto.transport.write(data)

    def connectionLost(self, why = connectionDone):
        self.__proto.connectionLost(why)

main proxy-server class:

class SSDMProtocol(LineReceiver)
...

After SSDMProtocol object (call obSSDMProtocol) parse headers it invoke method that open ftp connection (FTPClient from twisted.protocols.ftp) and set object of FTPManager field _ftpClientAsync and call _ftpCWDSuccees(self, protocol, fileName) with protocol = obSSDMProtocol and when file’s bytes recieved invokes dataReceived(self, data) of FileReceiver object.

And when self.__proto.transport.write(data) invoked, data appends to inner buffer faster than sending back to client, therefore memory runs out. May be I can stop reading when the buffer reaches a certain size and resume reading after buffer will be all send to client? or something like that?

  • 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-13T00:47:49+00:00Added an answer on June 13, 2026 at 12:47 am

    If you’re passing a 20 gigabyte (gigabit?) string to transport.write, you’re going to need at least 20 gigabytes (gigabits?) of memory – probably more like 40 or 60 due to the extra copying necessary when dealing with strings in Python.

    Even if you never pass a single string to transport.write that is 20 gigabytes (gigabits?), if you repeatedly call transport.write with short strings at a rate faster than your network can handle, the send buffer will eventually grow too large to fit in memory and you’ll encounter a MemoryError.

    The solution to both of these problems is the producer/consumer system. The advantage that using IProducer and IConsumer gives you is that you’ll never have a 20 gigabyte (gigabit?) string and you’ll never fill up a send buffer with too many shorter strings. The network will be throttled so that bytes are not read faster than your application can deal with them and forget about them. Your strings will end up on the order of 16kB – 64kB, which should easily fit in memory.

    You just need to adjust your use of FileReceiver to include registration of the incoming connection as a producer for the outgoing connection:

    class FileReceiver(Protocol):
        def __init__(self, outgoing):
            self._outgoing = outgoing
    
        def connectionMade(self):
            self._outgoing.transport.registerProducer(self.transport, streaming=True)
    
        def dataReceived(self, data):
            self._outgoing.transport.write(data)
    

    Now whenever self._outgoing.transport‘s send buffer fills up, it will tell self.transport to pause. Once the send buffer empties out, it will tell self.transport to resume. self.transport nows how to undertake these actions at the TCP level so that data coming into your server will also be slowed down.

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

Sidebar

Related Questions

I am currently trying to design a client-server application, something like this: the user
I'm trying to write a client-server application in Java with an XML-based protocol. But
I am trying to write a unit test for a client server application. To
I'm trying to write a client-server console application on C# using UDP. And i
I have started to write a Python 3.x client application. The server application exists
I have a need to write an client-server application where a tiny server rests
I am writing a netty client and server application that will write JVM GC
I have an application using sockets.. a client and server program like mySql.. I
My client/server application is using WCF for communication, which has been great. However one
I need to write a client-server application. I want to write it in 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.