Login Register






Need help with a script filter_list
Author
Message
RE: Need help with a script #4
My pleasure,
For commands, look at what your handel connection method is actually doing

Code:
def joke(): return "I really hate this damned machine\nI really wish they'd sell it\nIt never does quite what I want\nbut only what I tell it!" def anotherCommand(): file = open("Hello", 'w') file.write("anotherCommand makes a file!") file.close() print("Someone did a command!") return "You just did a command!" #Reason number ___ python is awesome: you can make arrays of methods with strings as indexes commandlist = {} commandlist["Joke"] = joke #Does the joke method commandlist["AnotherCommand"] = anotherCommand #Does the anotherCommand method def clientHandel(conn, addr) data = conn.recv(1024) #This waits till the connection has sent something, and stores it in data string = str(data, 'UTF-8') #Python sends bytes over, so we need to convert it to a string try: message = commandlist[string]() except: message = 'Failed to do command!' outputBytes = bytes(message, 'UTF-8') # need to turn it back into bytes before sending it conn.send(outputBytes) #Sends a message to the client

Reply





Messages In This Thread
Need help with a script - by TechSaavy - 12-11-2012, 05:59 PM
RE: Need help with a script - by 3SidedSquare - 12-18-2012, 03:52 AM
RE: Need help with a script - by TechSaavy - 12-18-2012, 03:39 PM
RE: Need help with a script - by 3SidedSquare - 12-18-2012, 11:21 PM
RE: Need help with a script - by TechSaavy - 12-19-2012, 04:27 PM