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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:26:06+00:00 2026-06-11T11:26:06+00:00

I’m trying to implement a small chat server-client pair in Python. I have already

  • 0

I’m trying to implement a small chat server-client pair in Python. I have already written both my server and my client, but I’m having a little problem trying to run the server on my website.

This example is from the docs. I modified it a little bit to support multiple clients:

#!/usr/bin/env python

import socket

TCP_IP = '127.0.0.1'
TCP_PORT = 9090
BUFFER_SIZE = 256

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, TCP_PORT))
s.listen(1)

while True:
    conn, addr = s.accept()
    print('Connection address:', addr)
    while True:
        data = conn.recv(BUFFER_SIZE)
        if not data: continue
        # handle the request 
    conn.close()

This server uses a while loop, which means that it should only be run once. However, I can’t figure out how to run the server only once.

I understand that I had to do socket.accept() inside a while loop in order to work with more than one client, but the problem is actually running it on my web server and making it wait for connections forever.

Help me! ~Chance

  • 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-11T11:26:08+00:00Added an answer on June 11, 2026 at 11:26 am

    For one thing, your server will handle multiple clients, but only one at a time. This is not so bad for request-response based servers (like a HTTP server). In your case, you probably want to keep an open connection to each client.

    You might want to take a look at the SocketServer library. This library will help you create a server that will handle multiple clients at the same time. For this you can use an ThreadingMixin.

    The example provided for this library is very much like a Chat Server, so you could use it as a basis for your own code.

    In the server you need to create list of connected clients. You should create a RequestHandlder that will read incoming data from the clients in an infinite loop. Upon receiving data from the client, it should send the data to all other clients in the list.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have an array which has BIG numbers and small numbers in it. I
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites 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.