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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:58:11+00:00 2026-06-14T04:58:11+00:00

When I run the client / server together, and try to send a message,

  • 0

When I run the client / server together, and try to send a message, it doesn’t seem like either of them recieves anything. Why?

client.py:

import socket, sys
import threading

# Client for WutChat #

PORT = 5000

queue = []

def exitClient(s):
    s.close()
    print "Exiting..."
    sys.exit()

def connect(host, port):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try: s.connect((host, port))
    except: return "error"
    return s

def recieveData(s):
    while True:
        data = s.recv(512)
        if not data: continue
        if data in queue:
            continue
        queue.append(data)
        print data

def sendData(s):
    while True:
        try: data = raw_input(">")
        except EOFError: exitClient(s)
        if data == "": print "no msg"; continue;
        if data.startswith("/"):
            print "Command detected"
            continue
        s.send(data)

if __name__ == "__main__":
    s = connect(sys.argv[1], int(sys.argv[2]))
    threading.Thread(target=recieveData, args=(s,)).start()
    threading.Thread(target=sendData, args=(s,)).start()

server.py:

import socket, sys
import threading

# Server for WutChat #

PORT = 5000
DEBUG = True

conns = {}
msgqueue = []

def connect():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try: s.bind(("", int(sys.argv[1])))
    except IndexError: s.bind(("", PORT))
    s.listen(1)

    while True:
        addr, obj = s.accept()
        conns[addr] = obj

        print str(addr)+" connected!"

        threading.Thread(target=handle, args=(addr, obj, s,)).start()


def handle(addr, obj, s):
    while True:
        try: msg = obj.recv(512)
        except:
            continue

        print msg
        msg = addr + msg

        msgqueue.append(msg)
        if DEBUG: print msgqueue

        for conn in conns:
            for message in msgqueue:
                conns[conn].send(message)
                del message

if __name__ == "__main__":
    connect()
  • 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-14T04:58:12+00:00Added an answer on June 14, 2026 at 4:58 am

    You have switched around the resulting tuple of accept:

    addr,obj = s.accept()
    

    should be

    obj,addr = s.accept()
    

    To find errors like these, remove the generic try..except block in handle, and catch only the specific errors you want to. In your specific case (if obj.recv fails), you can catch socket.error, but the only sensible thing to do when that happens is to close the socket and terminate the thread.

    On an unrelated note, you may want to have a more descriptive name than obj. How about client_sock or simply sock?

    Also,

    msg = addr + msg
    

    will fail because addr is a tuple, and msg a bytestring. You want

    msg = repr(addr).encode('utf-8') + msg
    

    Additionally,

    del message
    

    just removes the name message, and is a no-op in your case. You probably want to use Queue.get instead.

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

Sidebar

Related Questions

if separately Client ---send message to---> Server : works fine! if separately Server ---send
So I'm writing a program that is suppose to run forever (client server stuff)
I write client-server application. Client will run on android and server on plain java.
The Java hotspot vpm can be run with -client or -server argument. If neither
I run my client/server application with protobuf-net instead of binaryformatter and i get next
Well, I'm trying to run a client-server application with encryption using AES on VS
Is it possible to run client-server combination of VSS 2005 (client)/VSS 6.0 (server) on
I want to run my client program 25,000 times. I need to create a
I'm writing a simple program that will run entirely client-side. (Desktop programming? do people
Hi I am trying to run WSAD in Client login but its not starting

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.