I changed the Twisted program client server on this site a bit, which provided a program that could act as a server and client (http://stackoverflow.com/questions/3275004/how-to-write-a- twisted server-what- this-and-a-client). I can connect the client server to an external client on the one hand and to an external server on the other. I want to transfer data from an external client to an external server through a server-client program. The problem I am facing is getting the string received in the ServerProtocol class (in the server-client program) into the ClientProtocol class (in the server-client program). I tried several ways to do this, including trying to use the factory link, as you can see from def init , but I can't get it to work. (for now, I'm just sending literals back and forth to an external server and client) Here is the server-client code:
from twisted.internet import protocol, reactor from twisted.protocols import basic class ServerProtocol(basic.LineReceiver): def lineReceived(self, line): print "line recveived on server-client",line self.sendLine("Back at you from server-client") factory = protocol.ClientFactory() factory.protocol = ClientProtocol reactor.connectTCP('localhost', 1234, factory) class ClientProtocol(basic.LineReceiver): def __init__(self, factory): self.factory = factory def connectionMade(self): self.sendLine("Hello from server-client!")
I should mention that I can connect to the server-client program with an external server and an external client on ports 4321 and 1234, respectively, and they just responded. In addition, I have not shown many attempts to use the self.factory link. Any advice or suggestions would be greatly appreciated.
source share