client/server chat program
Donn Cave
donn at u.washington.edu
Tue Dec 11 12:47:34 EST 2001
Quoth "Jason Orendorff" <jason at jorendorff.com>:
| "neuromorphus" <neuromorphus at yahoo.com> wrote:
|> The client program continuously asks for 'raw_input' from the user,and
|> then sends the msg to the server to be broadcasted. However, I can't
|> output messages to the terminal/console, if the client program is
|> waiting for input.
| The best way to proceed is to read a few chapters of Stevens'
| excellent book, "Advanced Programming in the UNIX Environment".
| Many deep Unix secrets and aha! moments await.
| http://www.kohala.com/start/apue.html
|
| The answer, in summary:
| * Use select.select() to wait for input. Provide the list
| [sys.stdin, mysocket] to select. This is Unix-specific.
| * When select tells you that there's input waiting on stdin,
| use os.read(sys.stdin.fileno(), 1000) to get it.
For a little more UNIX trivia: sys.stdin.fileno() is always 0,
by definition. Likewise, sys.stdout.fileno() is 1, and stderr 2.
The file object is only a superfluous inconvenience.
Donn Cave, donn at u.washington.edu
More information about the Python-list
mailing list