Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: WIZnetInterface WIZwiki-W7500-lecture mbed
Fork of WIZwiki-W7500-lecture1-tcp by
main.cpp@3:90acfa2e24cb, 2016-02-01 (annotated)
- Committer:
 - bangbh
 - Date:
 - Mon Feb 01 01:22:53 2016 +0000
 - Revision:
 - 3:90acfa2e24cb
 - Parent:
 - 2:ba228e5b659c
 - Child:
 - 4:d164f370aa56
 
For lecture_TCP
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| joon874 | 0:d7c890f9ee69 | 1 | #include "mbed.h" | 
| joon874 | 0:d7c890f9ee69 | 2 | #include "EthernetInterface.h" | 
| joon874 | 0:d7c890f9ee69 | 3 | |
| joon874 | 0:d7c890f9ee69 | 4 | int main() { | 
| joon874 | 0:d7c890f9ee69 | 5 | |
| joon874 | 0:d7c890f9ee69 | 6 | EthernetInterface eth; | 
| bangbh | 2:ba228e5b659c | 7 | |
| bangbh | 2:ba228e5b659c | 8 | uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02}; | 
| bangbh | 2:ba228e5b659c | 9 | eth.init(mac_addr, "192.168.0.180", "255.255.255.0", "192.168.0.1"); // USE Static IP | 
| bangbh | 2:ba228e5b659c | 10 | //eth.init(mac_addr); //Use DHCP | 
| joon874 | 0:d7c890f9ee69 | 11 | eth.connect(); | 
| joon874 | 0:d7c890f9ee69 | 12 | |
| joon874 | 0:d7c890f9ee69 | 13 | printf("IP Address is %s\r\n", eth.getIPAddress()); | 
| joon874 | 0:d7c890f9ee69 | 14 | |
| bangbh | 2:ba228e5b659c | 15 | TCPSocketConnection tcp_sock; | 
| bangbh | 2:ba228e5b659c | 16 | tcp_sock.connect("192.168.0.244", 4545); | 
| bangbh | 3:90acfa2e24cb | 17 | char message[] = "Hello World!\r\n"; | 
| bangbh | 3:90acfa2e24cb | 18 | tcp_sock.send(message, sizeof(message)-1); | 
| joon874 | 0:d7c890f9ee69 | 19 | char buffer[400]; | 
| joon874 | 0:d7c890f9ee69 | 20 | int ret; | 
| bangbh | 3:90acfa2e24cb | 21 | while (true) | 
| bangbh | 3:90acfa2e24cb | 22 | { | 
| bangbh | 2:ba228e5b659c | 23 | ret = tcp_sock.receive(buffer, sizeof(buffer)-1); | 
| bangbh | 3:90acfa2e24cb | 24 | if (ret > 0) | 
| bangbh | 3:90acfa2e24cb | 25 | { | 
| bangbh | 3:90acfa2e24cb | 26 | buffer[ret] = '\0'; | 
| bangbh | 3:90acfa2e24cb | 27 | printf("Received %d chars from server: %s\n", ret, buffer); | 
| bangbh | 3:90acfa2e24cb | 28 | } | 
| joon874 | 0:d7c890f9ee69 | 29 | } | 
| bangbh | 3:90acfa2e24cb | 30 | |
| bangbh | 2:ba228e5b659c | 31 | tcp_sock.close(); | 
| joon874 | 0:d7c890f9ee69 | 32 | |
| joon874 | 0:d7c890f9ee69 | 33 | eth.disconnect(); | 
| bangbh | 3:90acfa2e24cb | 34 | |
| bangbh | 3:90acfa2e24cb | 35 | printf("Disconnected!"); | 
| joon874 | 0:d7c890f9ee69 | 36 | } | 
