Final Code 12/19/2015

Dependents:   DCS_FINAL_CODE

Committer:
DeWayneDennis
Date:
Sat Dec 19 21:57:34 2015 +0000
Revision:
0:b49935f48132
Final Code 12/19/2015

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DeWayneDennis 0:b49935f48132 1 /*
DeWayneDennis 0:b49935f48132 2 TCPSocketConnection.h
DeWayneDennis 0:b49935f48132 3 2014 Copyright (c) Seeed Technology Inc. All right reserved.
DeWayneDennis 0:b49935f48132 4
DeWayneDennis 0:b49935f48132 5 Author:lawliet zou(lawliet.zou@gmail.com)
DeWayneDennis 0:b49935f48132 6 2014-2-24
DeWayneDennis 0:b49935f48132 7
DeWayneDennis 0:b49935f48132 8 This library is free software; you can redistribute it and/or
DeWayneDennis 0:b49935f48132 9 modify it under the terms of the GNU Lesser General Public
DeWayneDennis 0:b49935f48132 10 License as published by the Free Software Foundation; either
DeWayneDennis 0:b49935f48132 11 version 2.1 of the License, or (at your option) any later version.
DeWayneDennis 0:b49935f48132 12
DeWayneDennis 0:b49935f48132 13 This library is distributed in the hope that it will be useful,
DeWayneDennis 0:b49935f48132 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
DeWayneDennis 0:b49935f48132 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
DeWayneDennis 0:b49935f48132 16 Lesser General Public License for more details.
DeWayneDennis 0:b49935f48132 17
DeWayneDennis 0:b49935f48132 18 You should have received a copy of the GNU Lesser General Public
DeWayneDennis 0:b49935f48132 19 License along with this library; if not, write to the Free Software
DeWayneDennis 0:b49935f48132 20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DeWayneDennis 0:b49935f48132 21 */
DeWayneDennis 0:b49935f48132 22
DeWayneDennis 0:b49935f48132 23 #ifndef TCPSOCKET_H
DeWayneDennis 0:b49935f48132 24 #define TCPSOCKET_H
DeWayneDennis 0:b49935f48132 25
DeWayneDennis 0:b49935f48132 26 #include "Socket.h"
DeWayneDennis 0:b49935f48132 27
DeWayneDennis 0:b49935f48132 28 /** TCP socket connection
DeWayneDennis 0:b49935f48132 29 */
DeWayneDennis 0:b49935f48132 30 class TCPSocketConnection: public Socket
DeWayneDennis 0:b49935f48132 31 {
DeWayneDennis 0:b49935f48132 32 friend class TCPSocketServer;
DeWayneDennis 0:b49935f48132 33
DeWayneDennis 0:b49935f48132 34 public:
DeWayneDennis 0:b49935f48132 35 /** TCP socket connection
DeWayneDennis 0:b49935f48132 36 */
DeWayneDennis 0:b49935f48132 37 TCPSocketConnection();
DeWayneDennis 0:b49935f48132 38
DeWayneDennis 0:b49935f48132 39 /** Connects this TCP socket to the server
DeWayneDennis 0:b49935f48132 40 \param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS.
DeWayneDennis 0:b49935f48132 41 \param port The host's port to connect to.
DeWayneDennis 0:b49935f48132 42 \return 0 on success, -1 on failure.
DeWayneDennis 0:b49935f48132 43 */
DeWayneDennis 0:b49935f48132 44 int connect(const char* host, const int port);
DeWayneDennis 0:b49935f48132 45
DeWayneDennis 0:b49935f48132 46 /** Check if the socket is connected
DeWayneDennis 0:b49935f48132 47 \return true if connected, false otherwise.
DeWayneDennis 0:b49935f48132 48 */
DeWayneDennis 0:b49935f48132 49 bool is_connected(void);
DeWayneDennis 0:b49935f48132 50
DeWayneDennis 0:b49935f48132 51 /** Send data to the remote host.
DeWayneDennis 0:b49935f48132 52 \param data The buffer to send to the host.
DeWayneDennis 0:b49935f48132 53 \param length The length of the buffer to send.
DeWayneDennis 0:b49935f48132 54 \return the number of written bytes on success (>=0) or -1 on failure
DeWayneDennis 0:b49935f48132 55 */
DeWayneDennis 0:b49935f48132 56 int send(char* data, int length);
DeWayneDennis 0:b49935f48132 57
DeWayneDennis 0:b49935f48132 58 /** Send all the data to the remote host.
DeWayneDennis 0:b49935f48132 59 \param data The buffer to send to the host.
DeWayneDennis 0:b49935f48132 60 \param length The length of the buffer to send.
DeWayneDennis 0:b49935f48132 61 \return the number of written bytes on success (>=0) or -1 on failure
DeWayneDennis 0:b49935f48132 62 */
DeWayneDennis 0:b49935f48132 63 int send_all(char* data, int length);
DeWayneDennis 0:b49935f48132 64
DeWayneDennis 0:b49935f48132 65 /** Receive data from the remote host.
DeWayneDennis 0:b49935f48132 66 \param data The buffer in which to store the data received from the host.
DeWayneDennis 0:b49935f48132 67 \param length The maximum length of the buffer.
DeWayneDennis 0:b49935f48132 68 \return the number of received bytes on success (>=0) or -1 on failure
DeWayneDennis 0:b49935f48132 69 */
DeWayneDennis 0:b49935f48132 70 int receive(char* data, int length);
DeWayneDennis 0:b49935f48132 71
DeWayneDennis 0:b49935f48132 72 /** Receive all the data from the remote host.
DeWayneDennis 0:b49935f48132 73 \param data The buffer in which to store the data received from the host.
DeWayneDennis 0:b49935f48132 74 \param length The maximum length of the buffer.
DeWayneDennis 0:b49935f48132 75 \return the number of received bytes on success (>=0) or -1 on failure
DeWayneDennis 0:b49935f48132 76 */
DeWayneDennis 0:b49935f48132 77 int receive_all(char* data, int length);
DeWayneDennis 0:b49935f48132 78
DeWayneDennis 0:b49935f48132 79 /* set the current socket */
DeWayneDennis 0:b49935f48132 80 void setSocket(int currentSocket);
DeWayneDennis 0:b49935f48132 81 };
DeWayneDennis 0:b49935f48132 82
DeWayneDennis 0:b49935f48132 83 #endif