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
thread).
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)
reader.start()
while 1:
x = raw_input("go>")
self.sock.send(x)
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
enter.
Any ideas/suggestions?
Thanks.
For example, I get this displayed:
[example]
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\>[cursor_is_here]
[/example]
...so I type something like.."ver" but I get
[example]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'ver' is not defined
>>>
[/example]
Now, if I start over and have...
[example]
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\>[cursor_is_here]
[/example]
..and I press the Enter key I end up with
[example]
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\>
>>>[cursor_is_here]
[/example]
So, I get the prompt, I hit enter, which then displays the ">>>" ..and
if I type "ver" there, I get back what I expect.
I just wish I didn't have to hit enter before being able to type a
command.