mbed socket API

Dependents:   EthernetInterface EthernetInterface_RSF EthernetInterface EthernetInterface ... more

Deprecated

This is an mbed 2 sockets library. For mbed 5, network sockets have been revised to better support additional network stacks and thread safety here.

Committer:
emilmont
Date:
Thu Jul 26 15:07:32 2012 +0000
Revision:
5:300e7ad2dc1d
Parent:
4:75988d748e4d
Child:
6:cd2e5559786d
Add Endpoint class and UDPPacket class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 3:e6474399e057 1 /* Copyright (C) 2012 mbed.org, MIT License
emilmont 3:e6474399e057 2 *
emilmont 3:e6474399e057 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
emilmont 3:e6474399e057 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
emilmont 3:e6474399e057 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
emilmont 3:e6474399e057 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
emilmont 3:e6474399e057 7 * furnished to do so, subject to the following conditions:
emilmont 3:e6474399e057 8 *
emilmont 3:e6474399e057 9 * The above copyright notice and this permission notice shall be included in all copies or
emilmont 3:e6474399e057 10 * substantial portions of the Software.
emilmont 3:e6474399e057 11 *
emilmont 3:e6474399e057 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
emilmont 3:e6474399e057 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
emilmont 3:e6474399e057 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
emilmont 3:e6474399e057 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
emilmont 3:e6474399e057 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
emilmont 3:e6474399e057 17 */
emilmont 3:e6474399e057 18
emilmont 3:e6474399e057 19 #ifndef TCPSOCKET_H
emilmont 3:e6474399e057 20 #define TCPSOCKET_H
emilmont 3:e6474399e057 21
emilmont 3:e6474399e057 22 #include "Socket/Socket.h"
emilmont 5:300e7ad2dc1d 23 #include "Socket/Endpoint.h"
emilmont 3:e6474399e057 24
emilmont 3:e6474399e057 25 /**
emilmont 3:e6474399e057 26 This is a C++ abstraction for TCP networking sockets.
emilmont 3:e6474399e057 27 */
emilmont 5:300e7ad2dc1d 28 class TCPSocketConnection : public Socket, Endpoint {
emilmont 3:e6474399e057 29 friend class TCPSocketServer;
emilmont 3:e6474399e057 30
emilmont 3:e6474399e057 31 public:
emilmont 3:e6474399e057 32 /** Instantiate a TCP Socket.
emilmont 3:e6474399e057 33 */
emilmont 3:e6474399e057 34 TCPSocketConnection();
emilmont 3:e6474399e057 35
emilmont 3:e6474399e057 36 ~TCPSocketConnection();
emilmont 3:e6474399e057 37
emilmont 3:e6474399e057 38 /** Connect the TCP Socket to the following host.
emilmont 3:e6474399e057 39 \param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS.
emilmont 3:e6474399e057 40 \param port The host's port to connect to.
emilmont 3:e6474399e057 41 \return 0 on success, -1 on failure.
emilmont 3:e6474399e057 42 */
emilmont 4:75988d748e4d 43 int connect(const char* host, const int port);
emilmont 3:e6474399e057 44
emilmont 3:e6474399e057 45 /** Send data to the remote host.
emilmont 3:e6474399e057 46 \param data The buffer to send to the host.
emilmont 3:e6474399e057 47 \param length The length of the buffer to send.
emilmont 3:e6474399e057 48 \param timeout The maximum amount of time in ms to wait while trying to send the buffer.
emilmont 3:e6474399e057 49 \return the number of written bytes on success (>=0) or -1 on failure
emilmont 3:e6474399e057 50 */
emilmont 3:e6474399e057 51 int send(char* data, int length, int timeout=0);
emilmont 3:e6474399e057 52
emilmont 3:e6474399e057 53 /** Send data to the remote host.
emilmont 3:e6474399e057 54 \param data The buffer to send to the host.
emilmont 3:e6474399e057 55 \param length The length of the buffer to send.
emilmont 3:e6474399e057 56 \param timeout The maximum amount of time in ms to wait while trying to send the buffer.
emilmont 3:e6474399e057 57 \return the number of written bytes on success (>=0) or -1 on failure
emilmont 3:e6474399e057 58 */
emilmont 3:e6474399e057 59 int send_all(char* data, int length, int timeout=0);
emilmont 3:e6474399e057 60
emilmont 3:e6474399e057 61 /** Receive data from the remote host.
emilmont 3:e6474399e057 62 \param data The buffer in which to store the data received from the host.
emilmont 3:e6474399e057 63 \param length The maximum length of the buffer.
emilmont 3:e6474399e057 64 \param timeout The maximum amount of time in ms to wait while trying to receive data.
emilmont 3:e6474399e057 65 \return the number of received bytes on success (>=0) or -1 on failure
emilmont 3:e6474399e057 66 */
emilmont 3:e6474399e057 67 int receive(char* data, int length, int timeout=0);
emilmont 3:e6474399e057 68
emilmont 3:e6474399e057 69 /** Receive data from the remote host.
emilmont 3:e6474399e057 70 \param data The buffer in which to store the data received from the host.
emilmont 3:e6474399e057 71 \param length The maximum length of the buffer.
emilmont 3:e6474399e057 72 \param timeout The maximum amount of time in ms to wait while trying to receive data.
emilmont 3:e6474399e057 73 \return the number of received bytes on success (>=0) or -1 on failure
emilmont 3:e6474399e057 74 */
emilmont 3:e6474399e057 75 int receive_all(char* data, int length, int timeout=0);
emilmont 5:300e7ad2dc1d 76
emilmont 3:e6474399e057 77 private:
emilmont 3:e6474399e057 78 bool _closedByRemoteHost;
emilmont 3:e6474399e057 79
emilmont 3:e6474399e057 80 };
emilmont 3:e6474399e057 81
emilmont 3:e6474399e057 82 #endif