Semester Project (part 3)
Keyboard input
- Client (may) want to accept periodic input from user
- Client must arrange for:
- "Raw" (unbuffered) input
- Wait (
select
) on keyboard input and server message
- Input from keyboard can be:
- Cooked: Buffered, control characters, sent to
process when
CR
entered
- Raw: Unbuffered, each keystroke sent to
process immediately
- Echoed: Keystrokes displayed on screen
Input modes
Changing input modes
ioctl
system call reads and writes termios
structure:
ioctl(fileno(stdin), TCGETS, &stdin_termios);
ioctl(fileno(stdin), TCSETS, &stdin_termios);
- Read
termios
structure, make changes, write to change
keyboard mode
- A polite client will restore the original modes on exit...
Waiting on keyboard input
- Use select to wait on both socket with server
connection and keyboard input
Client->server protocol
RESTART | 2 | Start initially or restart after ship
destroyed
|
TURN_LEFT | 16 | Rotate ship left
|
TURN_RIGHT | 17 | Rotate ship right
|
THRUSTER | 18 | Fire thruster
|
TORPEDO | 19 | Fire torpedo
|
HYPERSPACE | 20 | Go to hyperspace
|
- Each command is one octet (byte) long
- TURN_LEFT and TURN_RIGHT rotate the ship 0.01 revolution
Last revised 26 November 2006