Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: NNN50_CE_Test_UDP NNN50_linux_firmware NNN50_SoftAP_HelloWorld NNN50_BLEWIFISensor ... more
EthernetInterface/Socket/TCPSocketConnection.h@18:eb59b255b9e3, 2017-03-22 (annotated)
- Committer:
- tsungta
- Date:
- Wed Mar 22 03:26:26 2017 +0000
- Revision:
- 18:eb59b255b9e3
- Parent:
- 10:7fc160bd0246
- Child:
- 19:d47ed42a7e45
35:85cf8ec
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| tsungta | 10:7fc160bd0246 | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
| tsungta | 10:7fc160bd0246 | 2 | * |
| tsungta | 10:7fc160bd0246 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
| tsungta | 10:7fc160bd0246 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
| tsungta | 10:7fc160bd0246 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| tsungta | 10:7fc160bd0246 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| tsungta | 10:7fc160bd0246 | 7 | * furnished to do so, subject to the following conditions: |
| tsungta | 10:7fc160bd0246 | 8 | * |
| tsungta | 10:7fc160bd0246 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
| tsungta | 10:7fc160bd0246 | 10 | * substantial portions of the Software. |
| tsungta | 10:7fc160bd0246 | 11 | * |
| tsungta | 10:7fc160bd0246 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
| tsungta | 10:7fc160bd0246 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| tsungta | 10:7fc160bd0246 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| tsungta | 10:7fc160bd0246 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| tsungta | 10:7fc160bd0246 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| tsungta | 10:7fc160bd0246 | 17 | */ |
| tsungta | 10:7fc160bd0246 | 18 | |
| tsungta | 10:7fc160bd0246 | 19 | #ifndef TCPSOCKET_H |
| tsungta | 10:7fc160bd0246 | 20 | #define TCPSOCKET_H |
| tsungta | 10:7fc160bd0246 | 21 | |
| tsungta | 10:7fc160bd0246 | 22 | #include "Socket/Socket.h" |
| tsungta | 10:7fc160bd0246 | 23 | #include "Socket/Endpoint.h" |
| tsungta | 10:7fc160bd0246 | 24 | |
| tsungta | 10:7fc160bd0246 | 25 | #define TCP_BUFFER_SIZE SOCKET_BUFFER_MAX_LENGTH//Tsungta, set 0 if no buffer is required |
| tsungta | 10:7fc160bd0246 | 26 | |
| tsungta | 10:7fc160bd0246 | 27 | /** |
| tsungta | 10:7fc160bd0246 | 28 | TCP socket connection |
| tsungta | 10:7fc160bd0246 | 29 | */ |
| tsungta | 10:7fc160bd0246 | 30 | class TCPSocketConnection : public Socket, public Endpoint { |
| tsungta | 10:7fc160bd0246 | 31 | friend class TCPSocketServer; |
| tsungta | 10:7fc160bd0246 | 32 | |
| tsungta | 10:7fc160bd0246 | 33 | public: |
| tsungta | 10:7fc160bd0246 | 34 | /** TCP socket connection |
| tsungta | 10:7fc160bd0246 | 35 | */ |
| tsungta | 10:7fc160bd0246 | 36 | TCPSocketConnection(); |
| tsungta | 10:7fc160bd0246 | 37 | |
| tsungta | 10:7fc160bd0246 | 38 | /** Connects this TCP socket to the server |
| tsungta | 10:7fc160bd0246 | 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 | 10:7fc160bd0246 | 40 | \param port The host's port to connect to. |
| tsungta | 10:7fc160bd0246 | 41 | \return 0 on success, -1 on failure. |
| tsungta | 10:7fc160bd0246 | 42 | */ |
| tsungta | 10:7fc160bd0246 | 43 | int connect(const char* host, const int port); |
| tsungta | 10:7fc160bd0246 | 44 | |
| tsungta | 10:7fc160bd0246 | 45 | /** Check if the socket is connected |
| tsungta | 10:7fc160bd0246 | 46 | \return true if connected, false otherwise. |
| tsungta | 10:7fc160bd0246 | 47 | */ |
| tsungta | 10:7fc160bd0246 | 48 | bool is_connected(void); |
| tsungta | 10:7fc160bd0246 | 49 | |
| tsungta | 10:7fc160bd0246 | 50 | /** Send data to the remote host. |
| tsungta | 10:7fc160bd0246 | 51 | \param data The buffer to send to the host. |
| tsungta | 10:7fc160bd0246 | 52 | \param length The length of the buffer to send. |
| tsungta | 10:7fc160bd0246 | 53 | \return the number of written bytes on success (>=0) or -1 on failure |
| tsungta | 10:7fc160bd0246 | 54 | */ |
| tsungta | 10:7fc160bd0246 | 55 | int send(char* data, int length); |
| tsungta | 10:7fc160bd0246 | 56 | |
| tsungta | 10:7fc160bd0246 | 57 | /** Send all the data to the remote host. |
| tsungta | 10:7fc160bd0246 | 58 | \param data The buffer to send to the host. |
| tsungta | 10:7fc160bd0246 | 59 | \param length The length of the buffer to send. |
| tsungta | 10:7fc160bd0246 | 60 | \return the number of written bytes on success (>=0) or -1 on failure |
| tsungta | 10:7fc160bd0246 | 61 | */ |
| tsungta | 10:7fc160bd0246 | 62 | int send_all(char* data, int length); |
| tsungta | 10:7fc160bd0246 | 63 | |
| tsungta | 10:7fc160bd0246 | 64 | /** Receive data from the remote host. |
| tsungta | 10:7fc160bd0246 | 65 | \param data The buffer in which to store the data received from the host. |
| tsungta | 10:7fc160bd0246 | 66 | \param length The maximum length of the buffer. |
| tsungta | 10:7fc160bd0246 | 67 | \return the number of received bytes on success (>=0) or -1 on failure |
| tsungta | 10:7fc160bd0246 | 68 | */ |
| tsungta | 10:7fc160bd0246 | 69 | int receive(char* data, int length); |
| tsungta | 10:7fc160bd0246 | 70 | |
| tsungta | 10:7fc160bd0246 | 71 | /** Receive all the data from the remote host. |
| tsungta | 10:7fc160bd0246 | 72 | \param data The buffer in which to store the data received from the host. |
| tsungta | 10:7fc160bd0246 | 73 | \param length The maximum length of the buffer. |
| tsungta | 10:7fc160bd0246 | 74 | \return the number of received bytes on success (>=0) or -1 on failure |
| tsungta | 10:7fc160bd0246 | 75 | */ |
| tsungta | 10:7fc160bd0246 | 76 | int receive_all(char* data, int length); |
| tsungta | 10:7fc160bd0246 | 77 | |
| tsungta | 10:7fc160bd0246 | 78 | private: |
| tsungta | 10:7fc160bd0246 | 79 | bool _is_connected; |
| tsungta | 10:7fc160bd0246 | 80 | |
| tsungta | 10:7fc160bd0246 | 81 | }; |
| tsungta | 10:7fc160bd0246 | 82 | |
| tsungta | 10:7fc160bd0246 | 83 | #endif |
| tsungta | 10:7fc160bd0246 | 84 |