Twisted отправка больших файлов python

Я пытаюсь передавать изображения и прочие файлы по сети используя Twisted. Я использую для этого класс "FileSender" и в частности метод "beginFileTransfer", который я использую на сервере. Но файл принимается клиентом не полностью, и я не могу его открыть. При этом, если я отправляю маленький файл то он приходит. Так что проблема в размере. Подскажите как мне передавать большие файлы. Ниже привожу код сервера и клиента:

from twisted.internet.protocol import Protocol, connectionDone
from twisted.python import failure
from twisted.protocols.basic import FileSender
from twisted.internet.protocol import Factory
from twisted.internet.endpoints import TCP4ServerEndpoint
from twisted.internet import reactor


class TestServer(Protocol):

    def connectionMade(self):
        filesender = FileSender()
        f = open('00000.jpg', 'rb')
        filesender.beginFileTransfer(f, self.transport)


    def dataReceived(self, data: bytes):
        data = data.decode('UTF-8')
        print(data)

    def connectionLost(self, reason: failure.Failure = connectionDone):
        print("Server lost Connection")

class QOTDFactory(Factory):
    def buildProtocol(self, addr):
        return TestServer()

# 8007 is the port you want to run under. Choose something >1024
endpoint = TCP4ServerEndpoint(reactor, 8007, interface="127.0.0.1")
endpoint.listen(QOTDFactory())
reactor.run()

from twisted.internet.protocol import Protocol, ClientFactory, connectionDone
from sys import stdout
from twisted.protocols.basic import FileSender

from twisted.python import failure


class TestClient(Protocol):
    def connectionMade(self):
        print("Client did connection")

    def dataReceived(self, data):
        f = open('13.jpg', 'wb')
        f.write(data)
        self.transport.write("Client take connection".encode('UTF-8'))

    def connectionLost(self, reason: failure.Failure = connectionDone):
        print("Client lost Connection Protocol")

class EchoClientFactory(ClientFactory):
    def startedConnecting(self, connector):
        print('Started to connect.')

    def buildProtocol(self, addr):
        print('Connected.')
        return TestClient()

    def clientConnectionLost(self, connector, reason):
        print('Lost connection factory.  Reason:', reason)

    def clientConnectionFailed(self, connector, reason):
        print('Connection failed factory. Reason:', reason)

from twisted.internet import reactor
reactor.connectTCP('127.0.0.1', 8007, EchoClientFactory())
reactor.run()

Ответы (0 шт):