Re: [Twisted-Python] [newbie] server script with client functionality
Thanks for your reply.
I'm new to Twisted, so I'm not sure where to find information on this.
I had looked at the tutorial, but admittedly not gone all the way, as it didn't seem to address my problem. But it looks like this part of the tutorial actually does.
Then again, by that time, I felt a bit daunted by the Twisted framework (Protocols, Services, Factories and what not, all hooked into each other). So I've switched back to the socket module. While less neat, it does have the additional advantage that when exporting my script to other people, I don't have to ask them to install Twisted as well. But perhaps, in time, I will give Twisted another try. I'll certainly play with a few times more, to see if I can get the hang of it.
Anyway, thanks again,
ps: ah yes, I did mean reactor.run(). I had already gotten somewhat confused with the terminology.
Evert Rol wrote:
I'm trying to write a server script that can pass the received data on (acting as a client) to a next server. Say, server A receives data from client B, and then acts as client A (while keeping in contact with client B) for server C. I'm using it to pass data through an extra machine before reaching the actual machine, where the extra machine serves as a security measure (eg, if that gets hacked, that won't bring too may other things down).
I've been looking at creating a client at the moment that the server receives data (in the dataReceived() method), but then I get two factory.run() methods
do you mean reactor.run()? Factories usually just implement buildProtocol, and can be used to keep references to protocols and other stuff (see tutorial).
, and would also need to find a way to stop the client; that doesn't seem to be correct. Or perhaps using threads, but then I don't know how to pass the data from the server to client.
you don't need threads.
Best to me would to have both connections active, each on their own port, and when data is received, 'something' in the client part gets called that sends these data on. Alternatively, I could simply call an external program with the data as arguments from the server script, but I'd like a all-in-one solution if possible. Or perhaps I'm looking at this the wrong way? (Although I'd prefer not to try and turn 'server C' into 'client C'.)
what do you mean by turning 'server C' into 'client C'?
Any suggestions or pointers?
How many connections from A to C do you need? as many as for B to A? Since you're in control of both servers it might make sense to keep some connections open between A and C, and save some handshake-overhead.
The finger example comes close to what you need, you just have to make serverprotocolA and clientprotocolA aware of each other.
Thanks in advance,