Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 494527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:30:17+00:00 2026-05-13T05:30:17+00:00

I am working my way through learning Twisted, and have stumbled across something I’m

  • 0

I am working my way through learning Twisted, and have stumbled across something I’m not sure I’m terribly fond of – the “Twisted Command Prompt”. I am fiddling around with Twisted on my Windows machine, and tried running the “Chat” example:

from twisted.protocols import basic

class MyChat(basic.LineReceiver):
    def connectionMade(self):
        print "Got new client!"
        self.factory.clients.append(self)

    def connectionLost(self, reason):
        print "Lost a client!"
        self.factory.clients.remove(self)

    def lineReceived(self, line):
        print "received", repr(line)
        for c in self.factory.clients:
            c.message(line)

    def message(self, message):
        self.transport.write(message + '\n')


from twisted.internet import protocol
from twisted.application import service, internet

factory = protocol.ServerFactory()
factory.protocol = MyChat
factory.clients = []

application = service.Application("chatserver")
internet.TCPServer(1025, factory).setServiceParent(application)

However, to run this application as a Twisted server, I have to run it via the “Twisted Command Prompt”, with the command:

twistd -y chatserver.py

Is there any way to change the code (set Twisted configuration settings, etc) so that I can simply run it via:

python chatserver.py

I’ve Googled, but the search terms seem to be too vague to return any meaningful responses.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:30:17+00:00Added an answer on May 13, 2026 at 5:30 am

    I don’t know if it’s the best way to do this but what I do is instead of:

    application = service.Application("chatserver")
    internet.TCPServer(1025, factory).setServiceParent(application)
    

    you can do:

    from twisted.internet import reactor
    reactor.listenTCP(1025, factory)
    reactor.run()
    

    Sumarized if you want to have the two options (twistd and python):

    if __name__ == '__main__':
        from twisted.internet import reactor
        reactor.listenTCP(1025, factory)
        reactor.run()
    else:
        application = service.Application("chatserver")
        internet.TCPServer(1025, factory).setServiceParent(application)
    

    Hope it helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been learning Objective-C and Cocoa by working my way through the Hillegass book
I have been working my way through Scott Guthrie's excellent post on ASP.NET MVC
I'm starting out with wxPython and have been working my way through every tutorial
I'm currently working my way through the learning curve that is LINQ and I
I'm working my way through learning writing a COM control. I've got an example
I'm working through the problems in Project Euler as a way of learning Haskell,
am working my way through the Beginning iPad Development Apress book and have noticed
I'm working my way through some simple programs for learning Erlang, and whenever I
I'm still learning my way through iOS development and working with Core Data and
I've been slowly working my way through the list of Project Euler problems, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.