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