4
A simple server that distributes any incoming messages to all
5
connected clients. To use telnet to your device's IP address and type.
6
You can see the client's input in the serial monitor as well.
7
Using an Arduino Wiznet Ethernet shield.
10
* Ethernet shield attached to pins 10, 11, 12, 13
11
* Analog inputs attached to pins A0 through A5 (optional)
15
modified 10 August 2010
23
// Enter a MAC address and IP address for your controller below.
24
// The IP address will be dependent on your local network.
25
// gateway and subnet are optional:
26
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
27
IPAddress ip(192,168,1, 177);
28
IPAddress gateway(192,168,1, 1);
29
IPAddress subnet(255, 255, 0, 0);
31
// telnet defaults to port 23
33
boolean gotAMessage = false; // whether or not you got a message from the client yet
36
// initialize the ethernet device
37
Ethernet.begin(mac, ip, gateway, subnet);
38
// start listening for clients
40
// open the serial port
45
// wait for a new client:
46
Client client = server.available();
48
// when the client sends the first byte, say hello:
51
Serial.println("We have a new client");
52
client.println("Hello, client!");
56
// read the bytes incoming from the client:
57
char thisChar = client.read();
58
// echo the bytes back to the client:
59
server.write(thisChar);
60
// echo the bytes to the server as well:
61
Serial.print(thisChar);