Skip to content

Instantly share code, notes, and snippets.

@companje
Created July 3, 2014 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save companje/cf8db122687ae99ef244 to your computer and use it in GitHub Desktop.
Save companje/cf8db122687ae99ef244 to your computer and use it in GitHub Desktop.
Arduino socket server forwarding all data received on Serial port to all connected clients
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,2, 177);
IPAddress gateway(192,168, 2, 100);
IPAddress subnet(255, 255, 255, 0);
EthernetServer server(23);
void setup() {
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.begin(9600);
Serial.print("Server address:");
Serial.println(Ethernet.localIP());
}
void loop() {
while (Serial.available()>0) {
char ch = Serial.read();
server.write(ch);
Serial.write(ch);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment