. , python .
, , python, , , , Ashwini , pickle, ,
import pickle
from twisted.internet.protocol import Protocol, ClientFactory
from twisted.internet import reactor
from twisted.internet.endpoints import TCP4ClientEndpoint
class ClassSender(Protocol):
def dataReceived(self, data):
print pickle.loads(data)
def writeObject(self, _object):
pickle.dump(_object,self.transport)
class ClassSenderFactory(ClientFactory):
def buildProtocol(self, addr):
return ClassSender()
class MyClass(object):
def __init__(self,data):
self.data = data
def SendObject(protocol):
print "Sending"
protocol.writeObject(MyClass('some sample data'))
point = TCP4ClientEndpoint(reactor, "localhost", 8000)
d = point.connect(ClassSenderFactory())
d.addCallback(SendObject)
reactor.run()
8000 (localhost) TCP. , , .
, , .
, (http://twistedmatrix.com/documents/current/core/examples/echoserv.py) , get -.
The problem is that many angular cases must be taken into account. What if the data is divided into two blocks, so we can’t unlock it with one call? Fortunately, twisted provides a ready-made class for working with this so-called promising broker. If you control both ends of the wire, this can solve many of these problems for you. Take a look at: https://twistedmatrix.com/documents/12.2.0/core/howto/pb-intro.html
source
share