Some codes from Twisted Network Programming Essentials book.