title: Twisted: Close connection after connectTCP without losing other connections
body: <p>I'm new to Twisted, and I'm trying to figure out how to implement the following.
  I have a server, which takes a message from a client.  This server, however sends the message from the client to another server after it receives it.
  So it looks something like:</p>
  
  <pre><code>Client ---&gt;   Server1  ---&gt;   Server2
  </code></pre>
  
  <p>So Server1 in essence, acts as both a server and a client.  However, after Server1 sends information to Server2, I want to disconnect Server1 from Server2.  I'm not sure how I can do this.</p>
  
  <p>What I have now working is the Client sending information to Server1.  I then modify the input a bit, then do <code>reactor.connectTCP()</code> which succesfully connects and sends information to Server2.  My trouble is how can I close the connection without having to shut down Server1 completely.  I tried using <code>transport.loseConnection( )</code> but this shuts down Server1 when it disconnects from Server2.</p>
  
  <p>I'm thinking about using <code>reactor.spawnProcess()</code> in some way, but I can't get it to work.  From what I see, when I close the connection, it closes the process so if I can do connectTCP with another process, it shouldn't affect other processes.</p>
  
  <p>Here is my code</p>
  
  <pre><code>import time, datetime
  import re
  from twisted.internet import stdio, reactor, protocol
  from twisted.protocols import basic
  
  result = 'The AT message is unavailable (no previous talk with client)'
  
  class DataForwardingProtocol(protocol.Protocol):
      def __init__(self):
          self.output = None
          self.normalizeNewlines = False
  
      def dataReceived(self, data):
          if self.normalizeNewlines:
              data = re.sub(r"(\r\n|\n)", "\r\n", data)
          if self.output:
              self.output.write(data)
  
  class StdioProxyProtocol(DataForwardingProtocol):
      global result
      def connectionMade(self):
          inputForwarder = DataForwardingProtocol()
          inputForwarder.output = self.transport
          inputForwarder.normalizeNewlines = True
          stdioWrapper = stdio.StandardIO(inputForwarder)
          self.output = stdioWrapper
          self.transport.write(result)
          self.transport.loseConnection( )
  
  class StdioProxyFactory(protocol.ClientFactory):
      protocol = StdioProxyProtocol
  
      def clientConnectionLost(self, transport, reason):
          reactor.stop()
  
      def clientConnectionFailed(self, transport, reason):
          print reason.getErrorMessage()
          reactor.stop()
  
  class EchoProtocol(basic.LineReceiver):
  
      def dataReceived(self, line):
        #Do stuff with the input sent from the client.  This is irrelevant to my problem.
                  #UPDATE OTHER SERVERS
                  reactor.connectTCP('localhost', 12771, StdioProxyFactory())   
  
  class EchoServerFactory(protocol.ServerFactory):
      protocol = EchoProtocol
  
  if __name__ == "__main__":
      port = 12770
      reactor.listenTCP(port, EchoServerFactory( ))
      reactor.run( )
  </code></pre>
  
  <p>Thank you!</p>