Example of AWS IoT connection and Web Dashboard thru STM32 Nucleo evaluation board and mbed OS.
Dependencies: X_NUCLEO_IKS01A1 mbed FP MQTTPacket DnsQuery ATParser
TCPSocket.h
00001 /* TCPSocket 00002 * Copyright (c) 2015 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef TCPSOCKET_H 00018 #define TCPSOCKET_H 00019 00020 #include "Socket.h" 00021 #include "NetworkStack.h" 00022 00023 /** TCP socket connection 00024 */ 00025 class TCPSocket : public Socket { 00026 public: 00027 /** Create an uninitialized socket 00028 * 00029 * Must call open to initialize the socket on a network stack. 00030 */ 00031 TCPSocket(bool isTLS = false); 00032 00033 /** Create a socket on a network stack 00034 * 00035 * Creates and opens a socket on the specified network stack. 00036 * 00037 * @param iface Network stack as target for socket 00038 */ 00039 TCPSocket(NetworkStack *iface); 00040 00041 /** Opens a socket 00042 * 00043 * Creates a network socket on the specified network stack. 00044 * Not needed if stack is passed to the socket's constructor. 00045 * 00046 * @param iface Network stack as target for socket 00047 * @return 0 on success, negative error code on failure 00048 */ 00049 virtual int open(NetworkStack *iface); 00050 00051 /** Connects TCP socket to a remote host 00052 * 00053 * Initiates a connection to a remote server specified by either 00054 * a domain name or an IP address and a port. 00055 * 00056 * @param host Hostname of the remote host 00057 * @param port Port of the remote host 00058 * @return 0 on success, negative error code on failure 00059 */ 00060 int connect(const char *host, uint16_t port); 00061 00062 /** Connects TCP socket to a remote host 00063 * 00064 * Initiates a connection to a remote server specified by the 00065 * indicated address. 00066 * 00067 * @param address The SocketAddress of the remote host 00068 * @return 0 on success, negative error code on failure 00069 */ 00070 int connect(const SocketAddress &address); 00071 00072 /** Send data over a TCP socket 00073 * 00074 * The socket must be connected to a remote host. Returns the number of 00075 * bytes sent from the buffer. 00076 * 00077 * By default, send blocks until data is sent. If socket is set to 00078 * non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned 00079 * immediately. 00080 * 00081 * @param data Buffer of data to send to the host 00082 * @param size Size of the buffer in bytes 00083 * @return Number of sent bytes on success, negative error 00084 * code on failure 00085 */ 00086 int send(const void *data, unsigned size); 00087 00088 /** Receive data over a TCP socket 00089 * 00090 * The socket must be connected to a remote host. Returns the number of 00091 * bytes received into the buffer. 00092 * 00093 * By default, recv blocks until data is sent. If socket is set to 00094 * non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned 00095 * immediately. 00096 * 00097 * @param data Destination buffer for data received from the host 00098 * @param size Size of the buffer in bytes 00099 * @return Number of received bytes on success, negative error 00100 * code on failure 00101 */ 00102 int recv(void *data, unsigned size); 00103 00104 private: 00105 friend class TCPServer; 00106 00107 bool _isTLS; 00108 }; 00109 00110 #endif
Generated on Wed Jul 13 2022 20:28:49 by 1.7.2