This is a quick example of a simple HTTP client program using the network-socket API that is provided as a part of mbed-os. The program brings up an underlying network interface, and uses it to perform an HTTP transaction over a TCPSocket.

Committer:
mbed_official
Date:
Tue Mar 27 12:45:08 2018 +0100
Revision:
40:afef93b6d854
Parent:
33:d470701728e6
Child:
49:1923a727df5b
Merge branch 'mbed-os-5.8.0-oob'

* mbed-os-5.8.0-oob:
Updating mbed-os to mbed-os-5.8.0-rc2
Read until connection is properly closed.
Add build instructions.
Convert line-feeds for stdout.
Updating mbed-os to mbed-os-5.8.0-rc1

.
Commit copied from https://github.com/ARMmbed/mbed-os-example-sockets

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:17bd84fc5087 1 ### Getting started with the network-socket API ###
mbed_official 0:17bd84fc5087 2
mbed_official 0:17bd84fc5087 3 This is a quick example of a simple HTTP client program using the
mbed_official 33:d470701728e6 4 [network-socket API](https://os.mbed.com/docs/latest/reference/network-socket.html) that [Mbed OS](https://github.com/ARMmbed/mbed-os) provides.
mbed_official 0:17bd84fc5087 5
mbed_official 0:17bd84fc5087 6 The program brings up an underlying network interface, and uses it to perform an HTTP
mbed_official 0:17bd84fc5087 7 transaction over a TCPSocket.
mbed_official 0:17bd84fc5087 8
mbed_official 5:3e952c60d705 9 **Note:** The current example is limited to the ethernet interface on supported devices.
mbed_official 5:3e952c60d705 10 To use the example with a different interface, you will need to modify main.cpp and
mbed_official 5:3e952c60d705 11 replace the EthernetInterface class with the appropriate interface.
mbed_official 0:17bd84fc5087 12
mbed_official 40:afef93b6d854 13 ### Building
mbed_official 40:afef93b6d854 14
mbed_official 40:afef93b6d854 15 ```
mbed_official 40:afef93b6d854 16 mbed compile -t <toolchain> -m <target>
mbed_official 40:afef93b6d854 17 ```
mbed_official 40:afef93b6d854 18
mbed_official 40:afef93b6d854 19 For example, building for K64F using GCC: `mbed compile -t GCC_ARM -m K64F`
mbed_official 24:0449435e2ef2 20
mbed_official 13:ed9e4aa00044 21 ### Expected output ###
mbed_official 13:ed9e4aa00044 22
mbed_official 40:afef93b6d854 23 **Note:** The default serial port baud rate is 9600 bit/s.
mbed_official 40:afef93b6d854 24
mbed_official 13:ed9e4aa00044 25 ```
mbed_official 13:ed9e4aa00044 26 IP address: 10.118.14.45
mbed_official 13:ed9e4aa00044 27 Netmask: 255.255.252.0
mbed_official 13:ed9e4aa00044 28 Gateway: 10.118.12.1
mbed_official 13:ed9e4aa00044 29 sent 39 [GET / HTTP/1.1]
mbed_official 13:ed9e4aa00044 30 recv 173 [HTTP/1.1 200 OK]
mbed_official 13:ed9e4aa00044 31 External IP address: 217.140.111.135
mbed_official 13:ed9e4aa00044 32 Done
mbed_official 13:ed9e4aa00044 33 ```
mbed_official 13:ed9e4aa00044 34
mbed_official 0:17bd84fc5087 35 ### Documentation ###
mbed_official 0:17bd84fc5087 36
mbed_official 12:2e7466eba9a3 37 More information on the network-socket API can be found in the [mbed handbook](https://docs.mbed.com/docs/mbed-os-api-reference/en/latest/APIs/communication/network_sockets/).
mbed_official 33:d470701728e6 38
mbed_official 33:d470701728e6 39 ## Troubleshooting
mbed_official 33:d470701728e6 40
mbed_official 33:d470701728e6 41 If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.