V.06 11/3

Dependencies:   FT6206 SDFileSystem SPI_TFT_ILI9341 TFT_fonts

Fork of ATT_AWS_IoT_demo by attiot

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WNCTCPSocketConnection.h Source File

WNCTCPSocketConnection.h

00001 /* =====================================================================
00002    Copyright © 2016, Avnet (R)
00003 
00004    Contributors:
00005      * James M Flynn, www.em.avnet.com 
00006  
00007    Licensed under the Apache License, Version 2.0 (the "License"); 
00008    you may not use this file except in compliance with the License.
00009    You may obtain a copy of the License at
00010 
00011     http://www.apache.org/licenses/LICENSE-2.0
00012 
00013    Unless required by applicable law or agreed to in writing, 
00014    software distributed under the License is distributed on an 
00015    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
00016    either express or implied. See the License for the specific 
00017    language governing permissions and limitations under the License.
00018 
00019     @file          WNCInterface.cpp
00020     @version       1.0
00021     @date          Sept 2016
00022 
00023 ======================================================================== */
00024 
00025 #ifndef WNCTCPSOCKET_H
00026 #define WNCTCPSOCKET_H
00027 
00028 #include "WNCSocket/WNCSocket.h"
00029 #include "WNCSocket/WNCEndpoint.h"
00030 
00031 /**
00032 TCP socket connection
00033 */
00034 class WNCTCPSocketConnection : public WNCSocket, public WNCEndpoint {
00035     
00036 public:
00037     WNCTCPSocketConnection();
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     /** Set blocking or non-blocking mode of the socket and a timeout 
00080     \param  blocking true for blocking mode, false for non-blocking mode.
00081     \return none
00082     */
00083     void set_blocking (bool blocking, unsigned int timeout=1500);
00084 
00085     /** Close the socket
00086     \param none
00087     \return 0 if closed successfully, -1 on failure
00088     */
00089     int close(void);
00090 
00091 private:
00092     bool _is_blocking;
00093     unsigned int _btimeout;
00094 
00095 };
00096 
00097 #endif
00098