DEBJYOTI SINHA
/
Ethernet_Interface
Ethernet Interface example coding
main.cpp
- Committer:
- agaikwad
- Date:
- 2018-03-21
- Revision:
- 3:4f94cb9e70d0
- Parent:
- 1:965d7fb768b6
File content as of revision 3:4f94cb9e70d0:
#include "mbed.h" #include "EthernetInterface.h" // Network interface EthernetInterface net; // Socket demo int main() { // Bring up the ethernet interface printf("Reading Ethernet address:\n"); net.connect(); // Show the network address const char *ip = net.get_ip_address(); printf("IP address of device is: %s\n", ip ? ip : "No IP"); // Open a socket on the network interface, and create a TCP connection to mbed.org TCPSocket socket; socket.open(&net); socket.connect("www.arm.com", 80); // Send a simple http request char sbuffer[] = "GET / HTTP/1.1\r\nHost: www.arm.com\r\n\r\n"; int scount = socket.send(sbuffer, sizeof sbuffer); printf("sent %d [%.*s]\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer); // Recieve a simple http response and print out the response line char rbuffer[64]; int rcount = socket.recv(rbuffer, sizeof rbuffer); printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer); // Close the socket to return its memory and bring down the network interface socket.close(); // Bring down the ethernet interface net.disconnect(); printf("Done\n"); }