#include <SPI.h>
#include <Ethernet.h>
#include <string.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 2);
IPAddress myDns(0,0,0, 0);
IPAddress gateway(0, 0, 0, 0);
IPAddress subnet(255, 255, 255, 0);
EthernetServer server(23);
boolean alreadyConnected = false;
void setup() {
Ethernet.begin(mac, ip, myDns, gateway, subnet);
server.begin();
Serial.begin(9600);
while (!Serial) {
;
}
Serial.print("Chat server address:");
Serial.println(Ethernet.localIP());
}
void loop() {
EthernetClient client = server.available();
if (client) {
if (!alreadyConnected) {
client.flush();
alreadyConnected = true;
}
if (client.available() > 0) {
char thisChar = client.read();
server.write(thisChar);
Serial.write(thisChar);
}
}
}
For the block of code at the bottom instead of reading and echoing bytes I would like to read lines and echo lines and also add the char to a string. But I do not know how, can someone please give some advice on how to do this ?
What I have tried:
Arduino Forums, Youtube and Stackoverflow forums.