title: Initiating TCP Client after running reactor.run()
body: <p>I am trying to make a p2p app for sending just text messages. The way I am doing it is by having a server that keeps running as long as the application is running, and a client that connects to other node's server to send messages.
  For testing purposes I am doing it with localhost, i.e. talking to myself.</p>
  
  <p>So i have following:</p>
  
  <pre><code>from twisted.internet import reactor
  from mylib import MessageSFactory
  
  def send_message(message):
      reactor.connectTCP("localhost", 8080, MessageCFactory(message))
  
  reactor.listenTCP(8080, MessageSFactory())
  reactor.connectTCP("localhost", 8080, MessageCFactory("this message gets received"))
  reactor.run()
  
  send_message("this message doesn't")
  </code></pre>
  
  <p>However the problem is calling <code>send_message</code> (last line) after <code>reactor.run</code> seems to have no effect.</p>
  
  <p>The problem is I need to run the tcp client part (<code>connectTCP</code>) only when the user fills in a message, and sends it. So I am trying to do that with calling <code>send_message</code>. So how can I fix the above code to make that work?</p>
  
  <p>From what I have read so far, using <code>LoopingCall</code> would be the way to go, but than I have to store new messages the client inputs into a variable, and constantly check that variable for a new message and than run <code>send_message</code> This would result in a delay between the user input and the function callback, regardless is this my best option?</p>
  
  <p>Is there some other way to do it in this scenario? Or am I lacking understanding of some crucial part of <em>twisted</em>'s architecture?</p>
  
  <p>EDIT: As requested, here's the GUI code, that takes the message input from the client:</p>
  
  <pre><code>from Tkinter import *
  
  def send_message():
     print("message: %s" % (e1.get()))
  
  master = Tk()
  Label(master, text="Message").grid(row=0)
  e1 = Entry(master)
  e1.grid(row=0, column=1)
  Button(master, text='Send', command=send_message).grid(row=3, column=1, sticky=W, pady=4)
  mainloop()
  </code></pre>
  
  <p>Thanks</p>