1414
1515 created 18 Dec 2009
1616 by David A. Mellis
17- modified 4 Mar 2012
17+ modified 12 Mar 2012
1818 by Tom Igoe
1919
2020 */
2121
22-
2322#include < SPI.h>
2423#include < WiFi.h>
2524
2625char ssid[] = " YourNetwork" ; // your network SSID (name)
2726char pass[] = " password" ; // your network password (use for WPA, or use as key for WEP)
27+
2828int keyIndex = 0 ; // your network key Index number (needed only for WEP)
2929
3030int status = WL_IDLE_STATUS;
3131
3232WiFiServer server (23 );
3333
34- boolean gotAMessage = false ; // whether or not you got a message from the client yet
34+ boolean alreadyConnected = false ; // whether or not the client was connected previously
3535
3636void setup () {
3737 // initialize serial:
@@ -55,20 +55,25 @@ void loop() {
5555 // wait for a new client:
5656 WiFiClient client = server.available ();
5757
58+
5859 // when the client sends the first byte, say hello:
5960 if (client) {
60- if (!gotAMessage) {
61+ if (!alreadyConnected) {
62+ // clead out the input buffer:
63+ client.flush ();
6164 Serial.println (" We have a new client" );
6265 client.println (" Hello, client!" );
63- gotAMessage = true ;
64- }
66+ alreadyConnected = true ;
67+ }
6568
66- // read the bytes incoming from the client:
67- char thisChar = client.read ();
68- // echo the bytes back to the client:
69- server.write (thisChar);
70- // echo the bytes to the server as well:
71- Serial.print (thisChar);
69+ if (client.available () > 0 ) {
70+ // read the bytes incoming from the client:
71+ char thisChar = client.read ();
72+ // echo the bytes back to the client:
73+ server.write (thisChar);
74+ // echo the bytes to the server as well:
75+ Serial.write (thisChar);
76+ }
7277 }
7378}
7479
0 commit comments