Ethernet test for ECE 4180 and others to find your IP address and do a simple HTTP GET request over port 80.

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Committer:
mkersh3
Date:
Thu Apr 04 05:26:09 2013 +0000
Revision:
0:e7ca326e76ee
Ethernet Test for ECE4180 and others to find their IP Address and do a simple HTTP GET request over port 80.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mkersh3 0:e7ca326e76ee 1 /* Copyright (C) 2012 mbed.org, MIT License
mkersh3 0:e7ca326e76ee 2 *
mkersh3 0:e7ca326e76ee 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
mkersh3 0:e7ca326e76ee 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
mkersh3 0:e7ca326e76ee 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
mkersh3 0:e7ca326e76ee 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
mkersh3 0:e7ca326e76ee 7 * furnished to do so, subject to the following conditions:
mkersh3 0:e7ca326e76ee 8 *
mkersh3 0:e7ca326e76ee 9 * The above copyright notice and this permission notice shall be included in all copies or
mkersh3 0:e7ca326e76ee 10 * substantial portions of the Software.
mkersh3 0:e7ca326e76ee 11 *
mkersh3 0:e7ca326e76ee 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
mkersh3 0:e7ca326e76ee 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
mkersh3 0:e7ca326e76ee 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
mkersh3 0:e7ca326e76ee 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mkersh3 0:e7ca326e76ee 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
mkersh3 0:e7ca326e76ee 17 */
mkersh3 0:e7ca326e76ee 18
mkersh3 0:e7ca326e76ee 19 #ifndef TCPSOCKET_H
mkersh3 0:e7ca326e76ee 20 #define TCPSOCKET_H
mkersh3 0:e7ca326e76ee 21
mkersh3 0:e7ca326e76ee 22 #include "Socket/Socket.h"
mkersh3 0:e7ca326e76ee 23 #include "Socket/Endpoint.h"
mkersh3 0:e7ca326e76ee 24
mkersh3 0:e7ca326e76ee 25 /**
mkersh3 0:e7ca326e76ee 26 TCP socket connection
mkersh3 0:e7ca326e76ee 27 */
mkersh3 0:e7ca326e76ee 28 class TCPSocketConnection : public Socket, public Endpoint {
mkersh3 0:e7ca326e76ee 29 friend class TCPSocketServer;
mkersh3 0:e7ca326e76ee 30
mkersh3 0:e7ca326e76ee 31 public:
mkersh3 0:e7ca326e76ee 32 /** TCP socket connection
mkersh3 0:e7ca326e76ee 33 */
mkersh3 0:e7ca326e76ee 34 TCPSocketConnection();
mkersh3 0:e7ca326e76ee 35
mkersh3 0:e7ca326e76ee 36 /** Connects this TCP socket to the server
mkersh3 0:e7ca326e76ee 37 \param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS.
mkersh3 0:e7ca326e76ee 38 \param port The host's port to connect to.
mkersh3 0:e7ca326e76ee 39 \return 0 on success, -1 on failure.
mkersh3 0:e7ca326e76ee 40 */
mkersh3 0:e7ca326e76ee 41 int connect(const char* host, const int port);
mkersh3 0:e7ca326e76ee 42
mkersh3 0:e7ca326e76ee 43 /** Check if the socket is connected
mkersh3 0:e7ca326e76ee 44 \return true if connected, false otherwise.
mkersh3 0:e7ca326e76ee 45 */
mkersh3 0:e7ca326e76ee 46 bool is_connected(void);
mkersh3 0:e7ca326e76ee 47
mkersh3 0:e7ca326e76ee 48 /** Send data to the remote host.
mkersh3 0:e7ca326e76ee 49 \param data The buffer to send to the host.
mkersh3 0:e7ca326e76ee 50 \param length The length of the buffer to send.
mkersh3 0:e7ca326e76ee 51 \return the number of written bytes on success (>=0) or -1 on failure
mkersh3 0:e7ca326e76ee 52 */
mkersh3 0:e7ca326e76ee 53 int send(char* data, int length);
mkersh3 0:e7ca326e76ee 54
mkersh3 0:e7ca326e76ee 55 /** Send all the data to the remote host.
mkersh3 0:e7ca326e76ee 56 \param data The buffer to send to the host.
mkersh3 0:e7ca326e76ee 57 \param length The length of the buffer to send.
mkersh3 0:e7ca326e76ee 58 \return the number of written bytes on success (>=0) or -1 on failure
mkersh3 0:e7ca326e76ee 59 */
mkersh3 0:e7ca326e76ee 60 int send_all(char* data, int length);
mkersh3 0:e7ca326e76ee 61
mkersh3 0:e7ca326e76ee 62 /** Receive data from the remote host.
mkersh3 0:e7ca326e76ee 63 \param data The buffer in which to store the data received from the host.
mkersh3 0:e7ca326e76ee 64 \param length The maximum length of the buffer.
mkersh3 0:e7ca326e76ee 65 \return the number of received bytes on success (>=0) or -1 on failure
mkersh3 0:e7ca326e76ee 66 */
mkersh3 0:e7ca326e76ee 67 int receive(char* data, int length);
mkersh3 0:e7ca326e76ee 68
mkersh3 0:e7ca326e76ee 69 /** Receive all the data from the remote host.
mkersh3 0:e7ca326e76ee 70 \param data The buffer in which to store the data received from the host.
mkersh3 0:e7ca326e76ee 71 \param length The maximum length of the buffer.
mkersh3 0:e7ca326e76ee 72 \return the number of received bytes on success (>=0) or -1 on failure
mkersh3 0:e7ca326e76ee 73 */
mkersh3 0:e7ca326e76ee 74 int receive_all(char* data, int length);
mkersh3 0:e7ca326e76ee 75
mkersh3 0:e7ca326e76ee 76 private:
mkersh3 0:e7ca326e76ee 77 bool _is_connected;
mkersh3 0:e7ca326e76ee 78
mkersh3 0:e7ca326e76ee 79 };
mkersh3 0:e7ca326e76ee 80
mkersh3 0:e7ca326e76ee 81 #endif