[Twisted-Python] Writing a plug-in for an online game that uses UDP
Jp Calderone
exarkun at divmod.com
Sun Jul 25 19:50:24 MDT 2004
Ibrahim Mubarak wrote:
> Hi,
>
> [snip]
> def sendingOutput(self, result, host, port):
> """
> A callback for the deferred object returned
> """
> self.transport.write(str(result) + "\n" + str(self) + "\n", (host, port))
> return
>
> def datagramReceived(self, data, (host, port)):
> msg = data.split()
> if len(msg) != 1 and len(msg) != 3:
> self.sendingOutput("error" , host, port)
> return
>
> if msg[0] == "log" and len(msg) == 3:
> user = msg[1]
> pswd = msg[2]
> self.iiwuservice.logUser(user, pswd, host, port).addCallback(self.sendingOutput(self,
> host, port))
The above line is a problem. I believe you want it to read:
self.iiwuservice.logUser(user, pswd, host, port
).addCallback(self.sendingOutput, host, port
)
You cannot put self.sendingOutput(self, host, port) directly in the
arguments list, because Python would treat it like any other function
call: call it, and then use the return value as the argument to
addCallback(). In general,
d.addCallback(f, *a, **kw)
will lead to Twisted invoking f like this:
f(result, *a, **kw)
where result is the value with which the Deferred eventually fires.
Jp
More information about the Twisted-Python
mailing list