正确实例化协议以在python/twisted上发送消息

正确实例化协议以在python/twisted上发送消息,python,client-server,twisted,Python,Client Server,Twisted,我正在使用python中的一些客户机/服务器示例来建立一个简单的基于聊天的客户机 当我尝试发送消息时,GUI出现问题: class ChatFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, parent=None, title="Game Client") self.protocol = EchoProtocol # twisted Protocol sizer = wx.BoxSizer(w

我正在使用python中的一些客户机/服务器示例来建立一个简单的基于聊天的客户机

当我尝试发送消息时,GUI出现问题:

class ChatFrame(wx.Frame):
  def __init__(self):
    wx.Frame.__init__(self, parent=None, title="Game Client")
    self.protocol = EchoProtocol  # twisted Protocol

    sizer = wx.BoxSizer(wx.VERTICAL)
    self.text = wx.TextCtrl(self, style=wx.TE_MULTILINE | wx.TE_READONLY)
    self.ctrl = wx.TextCtrl(self, style=wx.TE_PROCESS_ENTER, size=(300, 25))

    sizer.Add(self.text, 5, wx.EXPAND)
    sizer.Add(self.ctrl, 0, wx.EXPAND)
    self.SetSizer(sizer)
    self.ctrl.Bind(wx.EVT_TEXT_ENTER, self.send)

  def send(self, evt):
    self.protocol.sendLine(str(self.ctrl.GetValue()))
    self.ctrl.SetValue("")
问题是,当我发送消息时,会出现以下错误:

TypeError: unbound method sendLine() must be called with EchoProtocol instance as first argument (got str instance instead)
我还试着换线

self.protocol=EchoProtocol#twisted协议

致:

协议=EchoProtocol() self.protocol=协议

我在这里得到的错误是:

Traceback (most recent call last):
  File "client.py", line 32, in send
    self.protocol.sendLine(str(self.ctrl.GetValue()))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/protocols/basic.py", line 625, in sendLine
    return self.transport.write(line + self.delimiter)
AttributeError: 'NoneType' object has no attribute 'write'

我的问题是如何调用send事件并正确发送消息

你读过客户指南吗?