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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:32:21+00:00 2026-06-18T22:32:21+00:00

I want to make a chat program on Python, such that I can send

  • 0

I want to make a chat program on Python, such that I can send as well as receive data.
I was thinking that I could have multiple threads running, one for the client and server each.
My Question is
How do I have multiple threads running in one file, for two classes?

My Current code:

from socket import *
from threading import Thread

class Server(Thread):
    def __init__(self,host,port,user):
        self.port = port
        self.host = host
        self.user = user
        self.bufsize = 1024
        self.addr = (host,port)

        self.socket = socket(AF_INET , SOCK_STREAM)
        self.socket.bind(self.addr)
        Thread.__init__(self)

    def run(self):
        self.socket.listen(5)
        while True:
            print 'Waiting for connection..'
            client, caddr = self.socket.accept()
            print 'Connected To',caddr

            data = client.recv(self.bufsize)
            if not data:
                continue
            print data         


class Client(Thread):
    def __init__(self,host,port,user):
        self.port = port
        self.host = host
        self.user = user
        self.bufsize = 1024
        self.addr = (host,port)

        self.socket = socket(AF_INET , SOCK_STREAM)
        Thread.__init__(self)

    def run(self):
        self.socket.connect(self.addr)
        while True:
            data = raw_input('> ')
            if not data:
                continue
            data = user+' said : '+data
            tcpClient.send(data)

host = ''
p1 = int(raw_input('Enter Port 1 : '))
p2 = int(raw_input('Enter Port 2 : '))
user = raw_input('Enter Your user: ').strip()

client = Client(host,p1,user)
server = Server(host,p2,user)

client.start()
server.start()

My current error msg:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Python2.7 For Chintoo\lib\threading.py", line 552, in __bootstrap_inner
    self.run()
  File "C:\Users\karuna\Desktop\Jython\Python\My Modules\Network\Chat.py", line 41, in run
    self.socket.connect(self.addr)
  File "C:\Python2.7 For Chintoo\lib\socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 10049] The requested address is not valid in its context
  • 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-18T22:32:22+00:00Added an answer on June 18, 2026 at 10:32 pm

    well, simply start multiple threads:

    from threading import Thread
    
    class Foo(Thread):
         def __init__(self):
             Thread.__init__(self)
             self.keepRunning = True
         def run(self):
             while self.keepRunning:
                print "running in thread", self
    
    import time
    if __name__ == "__main__":
         mythread1 = Foo()
         mythread2 = Foo()
         mythread1.start()
         mythread2.start()
         time.sleep(10) # and let the 2 threads to their work
         mythread1.keepRunning = False
         mythread2.keepRunning = False
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make it so that in my chat-application, links to websites can
I want to make a chat program like Google Wave that shows what is
I want to make it that one user on the site can chat request
I want to start to make a chat client that runs in web browsers,
i have a simple chat application in flex 3 and i want to make
I want to make a P2P Chat client, all I want it to do
I want make interactive application where user launches it and can do various task
I have style sheet with a class name changebackgroundcolor i want make change in
I have a card game program, and so far, the chat works great back
i want to make a chat room on gae ,(audio chat) has any framework

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.