Hi everyone. I'm writing a Twisted based daemon for a simple text-based multiplayer game. The game logic goes like this. The client sends a string in a particular format (command.arguments) to the server. The server receives that string, split it, and run the command along with the arguments. I already made it working.
One of the command called has to get data from database. I'm using Twistar to make things fancy. The problem is, I need to return the result of the deferred made by the query. I know it sounds so newbie, but this is my first Twisted program, and I'm still learning.
Well, I think the scripts will make things clearer:
The server.py (don't worry, it's inside a code tag):
I'm sure the error is in the login function. I think it's like saying "Wait. My result isn't here yet" by returning a deferred, but it will be the deferred which is sent to the client.
Well, there's no complicated logic yet. I started writing this just two days ago. All I want is to send the query_result.username to the client. The query is fine. I can print that thingy on the server.
What I want : the login() function returns the result of the query (a list, string or whatever) so I can send it to the client.
What I get : the login() function returns a deferred object.
The client is just a simple client which sends 'login.Sky Warden.123'. The arguments will be separated by the '.' as well.
I think that's all. Maybe it's just me who don't fully understand deferreds, or it's just a logic hole. Or maybe both. XD
Thank you everyone.
Edited by Sky Warden, 25 May 2013 - 01:09 AM.