Solve Twisted TypeError: unbound method doStart() must be called Factory


When I tried to bind Pyglet and twisted TCP Listener using connectTCP, I got this errors:

1
2
3
4
5
6
7
8
9
10
Traceback (most recent call last):
  File "pong.py", line 484, in <module>
    main()
  File "pong.py", line 477, in main
    reactor.connectTCP("122.248.232.186", 4005, TCPClientFactory)
  File "/usr/lib64/python2.7/site-packages/twisted/internet/posixbase.py", line 496, in connectTCP
    c.connect()
  File "/usr/lib64/python2.7/site-packages/twisted/internet/base.py", line 1044, in connect
    self.factory.doStart()
TypeError: unbound method doStart() must be called with TCPClientFactory instance as first argument (got nothing instead)


This is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Echo(Protocol):
    def dataReceived(self, data):
        print "received", repr(data)
       
        if len(data) > 1:
            self.pause_state.mobile_remote(data)
        else:
            self.game_state.mobile_remote(data)


class TCPClientFactory(ReconnectingClientFactory):
    def startedConnecting(self, connector):
        print ‘Started to connect.’

    def buildProtocol(self, addr):
        print ‘Connected.’
        print ‘Resetting reconnection delay’
        self.resetDelay()
        return Echo()

    def clientConnectionLost(self, connector, reason):
        print ‘Lost connection.  Reason:’, reason
        ReconnectingClientFactory.clientConnectionLost(self, connector, reason)

    def clientConnectionFailed(self, connector, reason):
        print ‘Connection failed. Reason:’, reason
        ReconnectingClientFactory.clientConnectionFailed(self, connector,
                                                         reason)

   
def main():
    game_state = GameState(width_window, height_window)
    pause_state = PausedState()
    game_start(game_state, pause_state)

    # schedule the update function, 60 times per second
    pyglet.clock.schedule_interval(update, 1.0/60.0)

    l = task.LoopingCall(game_state.looping)
    l.start(1/60)
    reactor.connectTCP("x.xx.xxx.xx", 4005, TCPClientFactory)

Then, I realized the mistake on this line :

1
reactor.connectTCP("x.xx.xxx.xx", 4005, TCPClientFactory)

Which is supposed to be :

1
reactor.connectTCP("x.xx.xxx.xx", 4005, TCPClientFactory())

Problem solved!


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.