Free Wed Editor CoffeeFreeHTML15.0

Dependencies:   WIZnetInterface mbed

Fork of WIZ_Proto_Makers_4th_Lab1 by Ricky Kwon

Committer:
Ricky_Kwon
Date:
Wed Feb 03 03:08:13 2016 +0000
Revision:
1:a4e5ec9f59cc
Parent:
0:722e7ff3a065
Child:
2:6a79ff33db7f
WIZ Proto Makers 3th Lab 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ricky_Kwon 0:722e7ff3a065 1 #include "mbed.h"
Ricky_Kwon 0:722e7ff3a065 2 #include "EthernetInterface.h"
Ricky_Kwon 0:722e7ff3a065 3
Ricky_Kwon 0:722e7ff3a065 4 #define WEB_SERVER_PORT 80
Ricky_Kwon 0:722e7ff3a065 5
Ricky_Kwon 0:722e7ff3a065 6 int main (void)
Ricky_Kwon 0:722e7ff3a065 7 {
Ricky_Kwon 0:722e7ff3a065 8 printf("Wait a second...\r\n");
Ricky_Kwon 0:722e7ff3a065 9 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02};
Ricky_Kwon 0:722e7ff3a065 10 const char ip_addr[] = "192.168.0.222";
Ricky_Kwon 0:722e7ff3a065 11 const char mask_addr[] = "255.255.255.0";
Ricky_Kwon 0:722e7ff3a065 12 const char gateway_addr[] = "192.168.0.1";
Ricky_Kwon 0:722e7ff3a065 13
Ricky_Kwon 0:722e7ff3a065 14 EthernetInterface eth;
Ricky_Kwon 0:722e7ff3a065 15 //eth.init(mac_addr); //Use DHCP
Ricky_Kwon 0:722e7ff3a065 16 eth.init(mac_addr, ip_addr, mask_addr, gateway_addr); //Use Static
Ricky_Kwon 0:722e7ff3a065 17 eth.connect();
Ricky_Kwon 0:722e7ff3a065 18 printf("Server IP Address is %s\r\n", eth.getIPAddress());
Ricky_Kwon 0:722e7ff3a065 19
Ricky_Kwon 0:722e7ff3a065 20 TCPSocketServer server;
Ricky_Kwon 0:722e7ff3a065 21 server.bind(WEB_SERVER_PORT);
Ricky_Kwon 0:722e7ff3a065 22 server.listen();
Ricky_Kwon 0:722e7ff3a065 23
Ricky_Kwon 0:722e7ff3a065 24 while (true)
Ricky_Kwon 0:722e7ff3a065 25 {
Ricky_Kwon 0:722e7ff3a065 26 printf("Wait for new connection...\r\n");
Ricky_Kwon 0:722e7ff3a065 27 TCPSocketConnection client;
Ricky_Kwon 0:722e7ff3a065 28 server.accept(client);
Ricky_Kwon 0:722e7ff3a065 29 client.set_blocking(false, 15000); // Timeout after (1.5)s
Ricky_Kwon 0:722e7ff3a065 30
Ricky_Kwon 0:722e7ff3a065 31 printf("Connection from: %s\r\n", client.get_address());
Ricky_Kwon 0:722e7ff3a065 32 char buffer[256];
Ricky_Kwon 0:722e7ff3a065 33
Ricky_Kwon 0:722e7ff3a065 34 while (true) {
Ricky_Kwon 0:722e7ff3a065 35
Ricky_Kwon 0:722e7ff3a065 36 wait(0.5);
Ricky_Kwon 0:722e7ff3a065 37 int n = client.receive_all(buffer, sizeof(buffer));
Ricky_Kwon 0:722e7ff3a065 38 if (n <= 0) break;
Ricky_Kwon 0:722e7ff3a065 39 //buffer[n] = '\0';
Ricky_Kwon 0:722e7ff3a065 40
Ricky_Kwon 0:722e7ff3a065 41 printf("rev_dat : %s\r\n", buffer);
Ricky_Kwon 1:a4e5ec9f59cc 42
Ricky_Kwon 0:722e7ff3a065 43 }
Ricky_Kwon 0:722e7ff3a065 44
Ricky_Kwon 0:722e7ff3a065 45 client.close();
Ricky_Kwon 0:722e7ff3a065 46 }
Ricky_Kwon 0:722e7ff3a065 47
Ricky_Kwon 0:722e7ff3a065 48 }
Ricky_Kwon 0:722e7ff3a065 49