The WDCInterface is is a drop-in replacement for an EthernetInterface class that allows the user to connect to the Internet with a Wistron NeWeb Corporation (WNC) M14A2A Series data module using the standard network Socket API's. This interface class is used in the AT&T Cellular IoT Starter Kit which is sold by Avnet (http://cloudconnectkits.org/product/att-cellular-iot-starter-kit).

Dependencies:   WncControllerK64F

Dependents:   WNCProximityMqtt Pubnub_ATT_IoT_SK_WNC_sync BluemixDemo BluemixQS ... more

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 TCPSOCKET_H
00026 #define TCPSOCKET_H
00027 
00028 #include "WncSocket.h"
00029 #include "WncEndpoint.h"
00030 
00031 /**
00032 TCP socket connection
00033 */
00034 class WncTCPSocketConnection : public WncSocket, public WncEndpoint {
00035     
00036 public:
00037     WncTCPSocketConnection(void) : _is_blocking(0),
00038         _btimeout(0);
00039 
00040     /** Connects this TCP socket to the server
00041     \param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS.
00042     \param port The host's port to connect to.
00043     \return 0 on success, -1 on failure.
00044     */    
00045     int connect(const char* host, const int port);
00046 
00047     /** Check if the socket is connected
00048     \return true if connected, false otherwise.
00049     */    
00050     bool is_connected(void);
00051 
00052     /** Send data to the remote host.
00053     \param data The buffer to send to the host.
00054     \param length The length of the buffer to send.
00055     \return the number of written bytes on success (>=0) or -1 on failure
00056      */    
00057     int send(char* data, int length);
00058     
00059     /** Send all the data to the remote host.
00060     \param data The buffer to send to the host.
00061     \param length The length of the buffer to send.
00062     \return the number of written bytes on success (>=0) or -1 on failure
00063     */
00064     int send_all(char* data, int length);
00065     
00066     /** Receive data from the remote host.
00067     \param data The buffer in which to store the data received from the host.
00068     \param length The maximum length of the buffer.
00069     \return the number of received bytes on success (>=0) or -1 on failure
00070      */
00071     int receive(char* data, int length);
00072     
00073     /** Receive all the data from the remote host.
00074     \param data The buffer in which to store the data received from the host.
00075     \param length The maximum length of the buffer.
00076     \return the number of received bytes on success (>=0) or -1 on failure
00077     */
00078     int receive_all(char* data, int length);
00079 
00080     /** Set blocking or non-blocking mode of the socket and a timeout 
00081     \param  blocking true for blocking mode, false for non-blocking mode.
00082     \return none
00083     */
00084     void set_blocking (bool blocking, unsigned int timeout=1500);
00085 
00086     /** Close the socket
00087     \param none
00088     \return 0 if closed successfully, -1 on failure
00089     */
00090     int close(void);
00091 
00092 private:
00093     bool _is_blocking;
00094     unsigned int _btimeout;
00095 
00096 };
00097 
00098 #endif