Hardware Reference
In-Depth Information
The serverEvent() message is
generated by the server when a new
client connects to it. serverEvent()
announces new clients and adds them
to the client list.
8
void serverEvent(Server myServer, Client thisClient) {
println("We have a new client: " + thisClient.ip());
clients.add(thisClient);
}
8
Finally, the keyReleased() method
sends any keystrokes typed on the
server to all connected clients.
void keyReleased() {
myServer.write(key);
}
The Clients
The pong client listens to local input and remote input. The local input is from you,
the user. The remote input is from the server. The client is constantly listening to
you, but it only listens to the server when it's connected.
To listen to you, the client needs:
read time
• An input for sending a connect message. The same
input can be used to send a disconnect message.
• An input for sending a left message.
• An input for sending a right message.
no
button pressed?
yes
connected?
To let the user know what the client device is doing, add:
no
yes
• An output to indicate whether the client is connected to
the server.
• An output to indicate when the connect/disconnect
button is pressed.
• An output to indicate when it's sending a left message.
• An output to indicate when it's sending a right message.
connect
disconnect
no
connected?
yes
It's always a good idea to put outputs on the client to give
local feedback when it receives input from the user. Even
if there is no connection to the server, local feedback lets
the user know that the client device is responding to her
actions. For example, pressing the connect/disconnect
button doesn't guarantee a connection, so it's important
to separate the output that acknowledges a button push
from the one that indicates successful connection. If
there's a problem, this helps the user determine whether
the problem is with the connection to the server, or with
the client device itself.
send interval
passed?
yes
Read sensor
state
< left
> right
send 'r'
send 'l'
middle range
Figure 5-2
Logic flowchart for the pong clients
Search WWH ::




Custom Search