UIPEthernet library for Arduino IDE, Eclipse with arduino plugin and MBED/SMeshStudio (AVR,STM32F,ESP8266,Intel ARC32,Nordic nRF51,Teensy boards,Realtek Ameba(RTL8195A,RTL8710)), ENC28j60 network chip. Compatible with Wiznet W5100 Ethernet library API. Compiled and tested on Nucleo-F302R8. Master repository is: https://github.com/UIPEthernet/UIPEthernet/
examples/TcpServer/TcpServer.ino
- Committer:
- cassyarduino
- Date:
- 2016-12-29
- Revision:
- 12:aef29fbc4a62
- Parent:
- 11:3fb19220d9ec
- Child:
- 17:be34a75aa9a7
File content as of revision 12:aef29fbc4a62:
/* * UIPEthernet EchoServer example. * * UIPEthernet is a TCP/IP stack that can be used with a enc28j60 based * Ethernet-shield. * * UIPEthernet uses the fine uIP stack by Adam Dunkels <adam@sics.se> * * ----------------- * * This Hello World example sets up a server at 192.168.1.6 on port 1000. * Telnet here to access the service. The uIP stack will also respond to * pings to test if you have successfully established a TCP connection to * the Arduino. * * This example was based upon uIP hello-world by Adam Dunkels <adam@sics.se> * Ported to the Arduino IDE by Adam Nielsen <malvineous@shikadi.net> * Adaption to Enc28J60 by Norbert Truchsess <norbert.truchsess@t-online.de> */ #if defined(__MBED__) #include <mbed.h> #include "mbed/millis.h" #define delay(x) wait_ms(x) #define PROGMEM #include "mbed/Print.h" #endif #include <UIPEthernet.h> #include "utility/logging.h" EthernetServer server = EthernetServer(1000); #if defined(ARDUINO) void setup() { #endif #if defined(__MBED__) int main() { #endif #if ACTLOGLEVEL>LOG_NONE #if defined(ARDUINO) LogObject.begin(9600); #endif #if defined(__MBED__) Serial LogObject(SERIAL_TX,SERIAL_RX); #endif #endif uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05}; IPAddress myIP(192,168,0,6); Ethernet.begin(mac,myIP); server.begin(); #if defined(ARDUINO) } void loop() { #endif #if defined(__MBED__) while(true) { #endif size_t size; if (EthernetClient client = server.available()) { while((size = client.available()) > 0) { uint8_t* msg = (uint8_t*)malloc(size+1); memset(msg, 0, size+1); size = client.read(msg,size); #if ACTLOGLEVEL>=LOG_INFO #if defined(ARDUINO) LogObject.write(msg,size); #endif #if defined(__MBED__) LogObject.uart_send_str(msg); #endif #endif free(msg); } #if ACTLOGLEVEL>=LOG_INFO LogObject.uart_send_strln(F("DATA from Server!")); #endif client.stop(); } } #if defined(__MBED__) } #endif