Client/Server socket send user input

jas codecraig at
Tue Oct 25 18:01:31 CEST 2005

I have a basic client/server socket situation setup....where the server
accepts a connection and then waits for commands.

On the client side, I create a socket, connect to the server...then I
pass the socket to a class which just reads from the socket (in a

class Reader(Thread):
    def run(self):
        while 1:
            print self.sock.recv(1),

Now, when the server sends back a message, and needs input back the
reader hangs at the sock.recv line...which is fine, and expected.
However, I want to be able to type something into the console at that
point and hit enter, and have it sent to the server.

In my client class I tried something like...

class Client(Thread):
    def run(self):
        reader = Reader(self.sock)
        while 1:
            x = raw_input("go>")
            print "sent", x

However, in order to see "go>" ..I have to hit enter first, then type
in my command and hit enter to send.  I just want to type and hit

Any ideas/suggestions?


More information about the Python-list mailing list