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 8786739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:42:55+00:00 2026-06-13T21:42:55+00:00

I have a server application written in python using twisted and I’d like to

  • 0

I have a server application written in python using twisted and I’d like to know how to kill instances of my protocol (bottalk). Everytime I get a new client connection, I see the instance in memory (print Factory.clients) .. but let’s say I want to kill one of those instances from the server side (drop a specific client connection)? Is this possible? I’ve tried looking for a phrase using lineReceived, then if it matches, self.transport.loseConnection(). But that doesn’t seem to reference the instance anymore or something..

class bottalk(LineReceiver):

    from os import linesep as delimiter

    def connectionMade(self):
            Factory.clients.append(self)
            print Factory.clients

    def lineReceived(self, line):
            for bots in Factory.clients[1:]:
                    bots.message(line)
            if line == "killme":
                    self.transport.loseConnection()

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

class botfactory(Factory):

    def buildProtocol(self, addr):
            return bottalk()

Factory.clients = []

stdio.StandardIO(bottalk())

reactor.listenTCP(8123, botfactory())

reactor.run()
  • 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-06-13T21:42:57+00:00Added an answer on June 13, 2026 at 9:42 pm

    You closed the TCP connection by calling loseConnection. But there’s no code anywhere in your application that removes items from the clients list on the factory.

    Try adding this to your protocol:

    def connectionLost(self, reason):
        Factory.clients.remove(self)
    

    This will remove the protocol instance from the clients list when the protocol’s connection is lost.

    Also, you should consider not using the global Factory.clients to implement this functionality. It’s bad for all the usual reasons globals are bad. Instead, give each protocol instance a reference to its factory and use that:

    class botfactory(Factory):
    
        def buildProtocol(self, addr):
            protocol = bottalk()
            protocol.factory = self
            return protocol
    
    factory = botfactory()
    factory.clients = []
    
    StandardIO(factory.buildProtocol(None))
    
    reactor.listenTCP(8123, factory)
    

    Now each bottalk instance can use self.factory.clients instead of Factory.clients.

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

Sidebar

Related Questions

I have a rather large client-server network application, written in Python. I'm using select.poll
Here's my question. Right now I have a Linux server application (written using C++
I have an asp.net web application written in C# using a SQL Server 2008
I have a network server application written in C, the listener is bound using
I have a simple blog application written in Python, using Django. I use Git
I have a client-server application written in Java using CORBA for the communication. The
I would like to have a client-server application written in .NET which would do
So i supose that i have a server application written in python import bottle
Background: I have written a java swing based client server application. The server is
Bckground I have a networked application written in C#. my server program has a

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.