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

  • SEARCH
  • Home
  • 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 8786333
In Process

The Archive Base Latest Questions

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

I am creating a chat server in python and got quite far as a

  • 0

I am creating a chat server in python and got quite far as a noob in the language. I am having 1 problem at the moment which I want to solve before I go further, but I cannot seem to find how to get the problem solved.

It is about a while loop that continues..

in the below code is where it goes wrong

while 1:
    try:
        data = self.channel.recv ( 1024 )
        print "Message from client: ", data
        if "exit" in data:
            self.channel.send("You have closed youre connection.\n")
            break
    except KeyboardInterrupt:
        break
    except:
        raise

When this piece of code get executed, on my client I need to enter “exit” to quit the connection. This works as a charm, but when I use CTRL+C to exit the connection, my server prints “Message from client: ” a couple of thousand times.

where am I going wrong?

  • 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:35:44+00:00Added an answer on June 13, 2026 at 9:35 pm

    You’re pressing Ctrl-C on the client side. This causes the server’s self.channel to get closed.

    Since calling recv() on a closed channel immediately returns a blank string, your server code gets stuck in an infinite loop.

    To fix this, add the following line to your server code:

    data = self.channel.recv ( 1024 )
    if not data: break # <<< ADD THIS
    

    Or, as suggested by @sr2222, you can combine both this and your current check into one:

    if not data or 'exit' in data: 
    

    This will exit the loop if the channel has been closed.

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

Sidebar

Related Questions

I'm creating a chat server which accepts both TCP and UDP connections. Assume for
I am creating a server chat program in java using DatagramSocket and datagramPacket im
I am creating a chat application using java sockets programming. I want to launch
I'm creating an Android chat application. I want chat screen to include features like
Problem : I am creating an iOS chat app using the XMPPFramework and an
I am working on creating a C# P2P chat messenger without a central server.
I'm creating a chat client which uses a database to check the status of
I am creating a chat application wherein I want to use smileys in the
I'm creating a chat daemon in python and twisted framework. And I'm wondering if
I'm creating a multithread chat client server application. In the server connection I use

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.