NNN50 WIFI_API library
Dependents: NNN50_CE_Test_UDP NNN50_linux_firmware NNN50_SoftAP_HelloWorld NNN50_BLEWIFISensor ... more
This is mbed compatible EthernetInterface lib exclude for Delta DFCM-NNN50 platform.
Additional information and examples can be found in mbed Handbook
EthernetInterface/Socket/TCPSocketConnection.h@32:8298a2fb074f, 2017-09-04 (annotated)
- Committer:
- tsungta
- Date:
- Mon Sep 04 05:40:11 2017 +0000
- Revision:
- 32:8298a2fb074f
56:f4cc53f; Add getRSSI() to readout RSSI while connected with AP router; Add SSL support refer to TCPSocketConnection.connect()
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| tsungta | 32:8298a2fb074f | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
| tsungta | 32:8298a2fb074f | 2 | * |
| tsungta | 32:8298a2fb074f | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
| tsungta | 32:8298a2fb074f | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
| tsungta | 32:8298a2fb074f | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| tsungta | 32:8298a2fb074f | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| tsungta | 32:8298a2fb074f | 7 | * furnished to do so, subject to the following conditions: |
| tsungta | 32:8298a2fb074f | 8 | * |
| tsungta | 32:8298a2fb074f | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
| tsungta | 32:8298a2fb074f | 10 | * substantial portions of the Software. |
| tsungta | 32:8298a2fb074f | 11 | * |
| tsungta | 32:8298a2fb074f | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
| tsungta | 32:8298a2fb074f | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| tsungta | 32:8298a2fb074f | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| tsungta | 32:8298a2fb074f | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| tsungta | 32:8298a2fb074f | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| tsungta | 32:8298a2fb074f | 17 | */ |
| tsungta | 32:8298a2fb074f | 18 | |
| tsungta | 32:8298a2fb074f | 19 | #ifndef TCPSOCKET_H |
| tsungta | 32:8298a2fb074f | 20 | #define TCPSOCKET_H |
| tsungta | 32:8298a2fb074f | 21 | |
| tsungta | 32:8298a2fb074f | 22 | #include "Socket/Socket.h" |
| tsungta | 32:8298a2fb074f | 23 | #include "Socket/Endpoint.h" |
| tsungta | 32:8298a2fb074f | 24 | |
| tsungta | 32:8298a2fb074f | 25 | #define TCP_BUFFER_SIZE SOCKET_BUFFER_MAX_LENGTH//Tsungta, set 0 if no buffer is required |
| tsungta | 32:8298a2fb074f | 26 | |
| tsungta | 32:8298a2fb074f | 27 | /** |
| tsungta | 32:8298a2fb074f | 28 | TCP socket connection |
| tsungta | 32:8298a2fb074f | 29 | */ |
| tsungta | 32:8298a2fb074f | 30 | class TCPSocketConnection : public Socket, public Endpoint { |
| tsungta | 32:8298a2fb074f | 31 | friend class TCPSocketServer; |
| tsungta | 32:8298a2fb074f | 32 | |
| tsungta | 32:8298a2fb074f | 33 | public: |
| tsungta | 32:8298a2fb074f | 34 | /** TCP socket connection |
| tsungta | 32:8298a2fb074f | 35 | */ |
| tsungta | 32:8298a2fb074f | 36 | TCPSocketConnection(); |
| tsungta | 32:8298a2fb074f | 37 | |
| tsungta | 32:8298a2fb074f | 38 | /** Connects this TCP socket to the server |
| tsungta | 32:8298a2fb074f | 39 | \param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS. |
| tsungta | 32:8298a2fb074f | 40 | \param port The host's port to connect to. |
| tsungta | 32:8298a2fb074f | 41 | \param sslSocket set true when SSL/TLS connection is used. |
| tsungta | 32:8298a2fb074f | 42 | \return 0 on success, -1 on failure. |
| tsungta | 32:8298a2fb074f | 43 | */ |
| tsungta | 32:8298a2fb074f | 44 | int connect(const char* host, const int port, bool sslSocket = false); |
| tsungta | 32:8298a2fb074f | 45 | |
| tsungta | 32:8298a2fb074f | 46 | /** Check if the socket is connected |
| tsungta | 32:8298a2fb074f | 47 | \return true if connected, false otherwise. |
| tsungta | 32:8298a2fb074f | 48 | */ |
| tsungta | 32:8298a2fb074f | 49 | bool is_connected(void); |
| tsungta | 32:8298a2fb074f | 50 | |
| tsungta | 32:8298a2fb074f | 51 | /** Send data to the remote host. |
| tsungta | 32:8298a2fb074f | 52 | \param data The buffer to send to the host. |
| tsungta | 32:8298a2fb074f | 53 | \param length The length of the buffer to send. |
| tsungta | 32:8298a2fb074f | 54 | \return the number of written bytes on success (>=0) or -1 on failure |
| tsungta | 32:8298a2fb074f | 55 | */ |
| tsungta | 32:8298a2fb074f | 56 | int send(char* data, int length); |
| tsungta | 32:8298a2fb074f | 57 | |
| tsungta | 32:8298a2fb074f | 58 | /** Send all the data to the remote host. |
| tsungta | 32:8298a2fb074f | 59 | \param data The buffer to send to the host. |
| tsungta | 32:8298a2fb074f | 60 | \param length The length of the buffer to send. |
| tsungta | 32:8298a2fb074f | 61 | \return the number of written bytes on success (>=0) or -1 on failure |
| tsungta | 32:8298a2fb074f | 62 | */ |
| tsungta | 32:8298a2fb074f | 63 | int send_all(char* data, int length); |
| tsungta | 32:8298a2fb074f | 64 | |
| tsungta | 32:8298a2fb074f | 65 | /** Receive data from the remote host. |
| tsungta | 32:8298a2fb074f | 66 | \param data The buffer in which to store the data received from the host. |
| tsungta | 32:8298a2fb074f | 67 | \param length The maximum length of the buffer. |
| tsungta | 32:8298a2fb074f | 68 | \return the number of received bytes on success (>=0) or -1 on failure |
| tsungta | 32:8298a2fb074f | 69 | */ |
| tsungta | 32:8298a2fb074f | 70 | int receive(char* data, int length); |
| tsungta | 32:8298a2fb074f | 71 | |
| tsungta | 32:8298a2fb074f | 72 | /** Receive all the data from the remote host. |
| tsungta | 32:8298a2fb074f | 73 | \param data The buffer in which to store the data received from the host. |
| tsungta | 32:8298a2fb074f | 74 | \param length The maximum length of the buffer. |
| tsungta | 32:8298a2fb074f | 75 | \return the number of received bytes on success (>=0) or -1 on failure |
| tsungta | 32:8298a2fb074f | 76 | */ |
| tsungta | 32:8298a2fb074f | 77 | int receive_all(char* data, int length); |
| tsungta | 32:8298a2fb074f | 78 | |
| tsungta | 32:8298a2fb074f | 79 | private: |
| tsungta | 32:8298a2fb074f | 80 | bool _is_connected; |
| tsungta | 32:8298a2fb074f | 81 | |
| tsungta | 32:8298a2fb074f | 82 | }; |
| tsungta | 32:8298a2fb074f | 83 | |
| tsungta | 32:8298a2fb074f | 84 | #endif |
| tsungta | 32:8298a2fb074f | 85 |