a library to use GPRS like ethernet or wifi, which makes it possible to connect to the internet with your GPRS module

Dependents:   Seeed_GPRS_Library_HelloWorld Seeed_GPRS_Xively_HelloWorld Seeed_ARCH_GPRS_V2_Xively_HelloWorld Seeed_ARCH_GPRS_V2_ThingSpeak_HelloWorld ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TCPSocketConnection.h Source File

TCPSocketConnection.h

00001 /*
00002   TCPSocketConnection.h
00003   2014 Copyright (c) Seeed Technology Inc.  All right reserved.
00004 
00005   Author:lawliet zou(lawliet.zou@gmail.com)
00006   2014-2-24
00007 
00008   This library is free software; you can redistribute it and/or
00009   modify it under the terms of the GNU Lesser General Public
00010   License as published by the Free Software Foundation; either
00011   version 2.1 of the License, or (at your option) any later version.
00012 
00013   This library is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   Lesser General Public License for more details.
00017 
00018   You should have received a copy of the GNU Lesser General Public
00019   License along with this library; if not, write to the Free Software
00020   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021 */
00022 
00023 #ifndef TCPSOCKET_H
00024 #define TCPSOCKET_H
00025 
00026 #include "Socket.h"
00027 
00028 /** TCP socket connection
00029  */
00030 class TCPSocketConnection: public Socket
00031 {
00032     friend class TCPSocketServer;
00033 
00034 public:
00035     /** TCP socket connection
00036     */
00037     TCPSocketConnection();
00038 
00039     /** Connects this TCP socket to the server
00040     \param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS.
00041     \param port The host's port to connect to.
00042     \return 0 on success, -1 on failure.
00043     */
00044     int connect(const char* host, const int port);
00045 
00046     /** Check if the socket is connected
00047     \return true if connected, false otherwise.
00048     */
00049     bool is_connected(void);
00050 
00051     /** Send data to the remote host.
00052     \param data The buffer to send to the host.
00053     \param length The length of the buffer to send.
00054     \return the number of written bytes on success (>=0) or -1 on failure
00055      */
00056     int send(char* data, int length);
00057 
00058     /** Send all the data to the remote host.
00059     \param data The buffer to send to the host.
00060     \param length The length of the buffer to send.
00061     \return the number of written bytes on success (>=0) or -1 on failure
00062     */
00063     int send_all(char* data, int length);
00064 
00065     /** Receive data from the remote host.
00066     \param data The buffer in which to store the data received from the host.
00067     \param length The maximum length of the buffer.
00068     \return the number of received bytes on success (>=0) or -1 on failure
00069      */
00070     int receive(char* data, int length);
00071 
00072     /** Receive all the data from the remote host.
00073     \param data The buffer in which to store the data received from the host.
00074     \param length The maximum length of the buffer.
00075     \return the number of received bytes on success (>=0) or -1 on failure
00076     */
00077     int receive_all(char* data, int length);
00078 };
00079 
00080 #endif