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
UDPSocket.h
00001 /* UDPSocket 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 UDPSOCKET_H 00018 #define UDPSOCKET_H 00019 00020 #include "Socket.h" 00021 #include "NetworkStack.h" 00022 00023 /** UDP socket 00024 */ 00025 class UDPSocket : public Socket { 00026 public: 00027 /** Create an uninitialized socket 00028 * 00029 * Must call open to initialize the socket on a network stack. 00030 */ 00031 UDPSocket(); 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 UDPSocket(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 /** Send a packet over a UDP socket 00052 * 00053 * Sends data to the specified address specified by either a domain name 00054 * or an IP address and port. Returns the number of bytes sent from the 00055 * buffer. 00056 * 00057 * By default, sendto blocks until data is sent. If socket is set to 00058 * non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned 00059 * immediately. 00060 * 00061 * @param host Hostname of the remote host 00062 * @param port Port of the remote host 00063 * @param data Buffer of data to send to the host 00064 * @param size Size of the buffer in bytes 00065 * @return Number of sent bytes on success, negative error 00066 * code on failure 00067 */ 00068 int sendto(const char *host, uint16_t port, const void *data, unsigned size); 00069 00070 /** Send a packet over a UDP socket 00071 * 00072 * Sends data to the specified address. Returns the number of bytes 00073 * sent from the buffer. 00074 * 00075 * By default, sendto blocks until data is sent. If socket is set to 00076 * non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned 00077 * immediately. 00078 * 00079 * @param address The SocketAddress of the remote host 00080 * @param data Buffer of data to send to the host 00081 * @param size Size of the buffer in bytes 00082 * @return Number of sent bytes on success, negative error 00083 * code on failure 00084 */ 00085 int sendto(const SocketAddress &address, const void *data, unsigned size); 00086 00087 /** Receive a packet over a UDP socket 00088 * 00089 * Receives data and stores the source address in address if address 00090 * is not NULL. Returns the number of bytes received into the buffer. 00091 * 00092 * By default, recvfrom blocks until data is sent. If socket is set to 00093 * non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned 00094 * immediately. 00095 * 00096 * @param address Destination for the source address or NULL 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 recvfrom(SocketAddress *address, void *data, unsigned size); 00103 }; 00104 00105 #endif
Generated on Wed Jul 13 2022 20:28:49 by 1.7.2