Ethernetwebsoc

Dependencies:   C12832_lcd LM75B WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Committer:
GordonSin
Date:
Fri May 31 04:09:54 2013 +0000
Revision:
0:0ed2a7c7190c
31/5/2013;

Who changed what in which revision?

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