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.
Fork of GPRSInterface by
Socket/TCPSocketConnection.h@1:7298a7950f65, 2014-02-25 (annotated)
- Committer:
- lawliet
- Date:
- Tue Feb 25 05:56:19 2014 +0000
- Revision:
- 1:7298a7950f65
- Parent:
- 0:8ccbd963e74d
version 1.0(update some code)
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| lawliet | 0:8ccbd963e74d | 1 | /* |
| lawliet | 0:8ccbd963e74d | 2 | TCPSocketConnection.h |
| lawliet | 0:8ccbd963e74d | 3 | 2014 Copyright (c) Seeed Technology Inc. All right reserved. |
| lawliet | 0:8ccbd963e74d | 4 | |
| lawliet | 0:8ccbd963e74d | 5 | Author:lawliet zou(lawliet.zou@gmail.com) |
| lawliet | 0:8ccbd963e74d | 6 | 2014-2-24 |
| lawliet | 0:8ccbd963e74d | 7 | |
| lawliet | 0:8ccbd963e74d | 8 | This library is free software; you can redistribute it and/or |
| lawliet | 0:8ccbd963e74d | 9 | modify it under the terms of the GNU Lesser General Public |
| lawliet | 0:8ccbd963e74d | 10 | License as published by the Free Software Foundation; either |
| lawliet | 0:8ccbd963e74d | 11 | version 2.1 of the License, or (at your option) any later version. |
| lawliet | 0:8ccbd963e74d | 12 | |
| lawliet | 0:8ccbd963e74d | 13 | This library is distributed in the hope that it will be useful, |
| lawliet | 0:8ccbd963e74d | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| lawliet | 0:8ccbd963e74d | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| lawliet | 0:8ccbd963e74d | 16 | Lesser General Public License for more details. |
| lawliet | 0:8ccbd963e74d | 17 | |
| lawliet | 0:8ccbd963e74d | 18 | You should have received a copy of the GNU Lesser General Public |
| lawliet | 0:8ccbd963e74d | 19 | License along with this library; if not, write to the Free Software |
| lawliet | 0:8ccbd963e74d | 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| lawliet | 0:8ccbd963e74d | 21 | */ |
| lawliet | 0:8ccbd963e74d | 22 | |
| lawliet | 0:8ccbd963e74d | 23 | #ifndef TCPSOCKET_H |
| lawliet | 0:8ccbd963e74d | 24 | #define TCPSOCKET_H |
| lawliet | 0:8ccbd963e74d | 25 | |
| lawliet | 0:8ccbd963e74d | 26 | #include "Socket.h" |
| lawliet | 0:8ccbd963e74d | 27 | |
| lawliet | 1:7298a7950f65 | 28 | /** TCP socket connection |
| lawliet | 1:7298a7950f65 | 29 | */ |
| lawliet | 1:7298a7950f65 | 30 | class TCPSocketConnection: public Socket |
| lawliet | 0:8ccbd963e74d | 31 | { |
| lawliet | 0:8ccbd963e74d | 32 | friend class TCPSocketServer; |
| lawliet | 0:8ccbd963e74d | 33 | |
| lawliet | 0:8ccbd963e74d | 34 | public: |
| lawliet | 0:8ccbd963e74d | 35 | /** TCP socket connection |
| lawliet | 0:8ccbd963e74d | 36 | */ |
| lawliet | 0:8ccbd963e74d | 37 | TCPSocketConnection(); |
| lawliet | 0:8ccbd963e74d | 38 | |
| lawliet | 0:8ccbd963e74d | 39 | /** Connects this TCP socket to the server |
| lawliet | 0:8ccbd963e74d | 40 | \param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS. |
| lawliet | 0:8ccbd963e74d | 41 | \param port The host's port to connect to. |
| lawliet | 0:8ccbd963e74d | 42 | \return 0 on success, -1 on failure. |
| lawliet | 0:8ccbd963e74d | 43 | */ |
| lawliet | 0:8ccbd963e74d | 44 | int connect(const char* host, const int port); |
| lawliet | 0:8ccbd963e74d | 45 | |
| lawliet | 0:8ccbd963e74d | 46 | /** Check if the socket is connected |
| lawliet | 0:8ccbd963e74d | 47 | \return true if connected, false otherwise. |
| lawliet | 0:8ccbd963e74d | 48 | */ |
| lawliet | 0:8ccbd963e74d | 49 | bool is_connected(void); |
| lawliet | 0:8ccbd963e74d | 50 | |
| lawliet | 0:8ccbd963e74d | 51 | /** Send data to the remote host. |
| lawliet | 0:8ccbd963e74d | 52 | \param data The buffer to send to the host. |
| lawliet | 0:8ccbd963e74d | 53 | \param length The length of the buffer to send. |
| lawliet | 0:8ccbd963e74d | 54 | \return the number of written bytes on success (>=0) or -1 on failure |
| lawliet | 0:8ccbd963e74d | 55 | */ |
| lawliet | 0:8ccbd963e74d | 56 | int send(char* data, int length); |
| lawliet | 0:8ccbd963e74d | 57 | |
| lawliet | 0:8ccbd963e74d | 58 | /** Send all the data to the remote host. |
| lawliet | 0:8ccbd963e74d | 59 | \param data The buffer to send to the host. |
| lawliet | 0:8ccbd963e74d | 60 | \param length The length of the buffer to send. |
| lawliet | 0:8ccbd963e74d | 61 | \return the number of written bytes on success (>=0) or -1 on failure |
| lawliet | 0:8ccbd963e74d | 62 | */ |
| lawliet | 0:8ccbd963e74d | 63 | int send_all(char* data, int length); |
| lawliet | 0:8ccbd963e74d | 64 | |
| lawliet | 0:8ccbd963e74d | 65 | /** Receive data from the remote host. |
| lawliet | 0:8ccbd963e74d | 66 | \param data The buffer in which to store the data received from the host. |
| lawliet | 0:8ccbd963e74d | 67 | \param length The maximum length of the buffer. |
| lawliet | 0:8ccbd963e74d | 68 | \return the number of received bytes on success (>=0) or -1 on failure |
| lawliet | 0:8ccbd963e74d | 69 | */ |
| lawliet | 0:8ccbd963e74d | 70 | int receive(char* data, int length); |
| lawliet | 0:8ccbd963e74d | 71 | |
| lawliet | 0:8ccbd963e74d | 72 | /** Receive all the data from the remote host. |
| lawliet | 0:8ccbd963e74d | 73 | \param data The buffer in which to store the data received from the host. |
| lawliet | 0:8ccbd963e74d | 74 | \param length The maximum length of the buffer. |
| lawliet | 0:8ccbd963e74d | 75 | \return the number of received bytes on success (>=0) or -1 on failure |
| lawliet | 0:8ccbd963e74d | 76 | */ |
| lawliet | 0:8ccbd963e74d | 77 | int receive_all(char* data, int length); |
| lawliet | 0:8ccbd963e74d | 78 | }; |
| lawliet | 0:8ccbd963e74d | 79 | |
| lawliet | 0:8ccbd963e74d | 80 | #endif |
