Customized
Dependents: MurataTypeYD_RPC_Sample
Fork of SNICInterface_mod by
Socket/TCPSocketConnection.h@12:0254eaccfda2, 2014-03-25 (annotated)
- Committer:
- kishino
- Date:
- Tue Mar 25 01:42:25 2014 +0000
- Revision:
- 12:0254eaccfda2
- Parent:
- 4:99cc93fe7d88
- Child:
- 14:54378c96d285
Refactoring of the class name
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kishino | 4:99cc93fe7d88 | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
kishino | 4:99cc93fe7d88 | 2 | * |
kishino | 4:99cc93fe7d88 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
kishino | 4:99cc93fe7d88 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
kishino | 4:99cc93fe7d88 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
kishino | 4:99cc93fe7d88 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
kishino | 4:99cc93fe7d88 | 7 | * furnished to do so, subject to the following conditions: |
kishino | 4:99cc93fe7d88 | 8 | * |
kishino | 4:99cc93fe7d88 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
kishino | 4:99cc93fe7d88 | 10 | * substantial portions of the Software. |
kishino | 4:99cc93fe7d88 | 11 | * |
kishino | 4:99cc93fe7d88 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
kishino | 4:99cc93fe7d88 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
kishino | 4:99cc93fe7d88 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
kishino | 4:99cc93fe7d88 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kishino | 4:99cc93fe7d88 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
kishino | 4:99cc93fe7d88 | 17 | */ |
kishino | 4:99cc93fe7d88 | 18 | |
kishino | 4:99cc93fe7d88 | 19 | #ifndef TCPSOCKET_H |
kishino | 4:99cc93fe7d88 | 20 | #define TCPSOCKET_H |
kishino | 4:99cc93fe7d88 | 21 | |
kishino | 4:99cc93fe7d88 | 22 | #include "Socket.h" |
kishino | 4:99cc93fe7d88 | 23 | #include "Endpoint.h" |
kishino | 4:99cc93fe7d88 | 24 | |
kishino | 4:99cc93fe7d88 | 25 | namespace murata_wifi |
kishino | 4:99cc93fe7d88 | 26 | { |
kishino | 4:99cc93fe7d88 | 27 | |
kishino | 4:99cc93fe7d88 | 28 | /** |
kishino | 4:99cc93fe7d88 | 29 | TCP socket connection |
kishino | 4:99cc93fe7d88 | 30 | */ |
kishino | 4:99cc93fe7d88 | 31 | class TCPSocketConnection : public Socket, public Endpoint { |
kishino | 4:99cc93fe7d88 | 32 | |
kishino | 4:99cc93fe7d88 | 33 | public: |
kishino | 4:99cc93fe7d88 | 34 | /** TCP socket connection |
kishino | 4:99cc93fe7d88 | 35 | */ |
kishino | 4:99cc93fe7d88 | 36 | TCPSocketConnection(); |
kishino | 4:99cc93fe7d88 | 37 | |
kishino | 4:99cc93fe7d88 | 38 | /** Connects this TCP socket to the server |
kishino | 12:0254eaccfda2 | 39 | @param host The ip address to connect to.(hexadecimal)("192.168.0.1"->0xC0A80001) |
kishino | 12:0254eaccfda2 | 40 | @param port The host's port to connect to. |
kishino | 12:0254eaccfda2 | 41 | @return 0 on success, -1 on failure. |
kishino | 12:0254eaccfda2 | 42 | @note This function is blocked until a returns. |
kishino | 12:0254eaccfda2 | 43 | When you use it by UI thread, be careful. |
kishino | 4:99cc93fe7d88 | 44 | */ |
kishino | 12:0254eaccfda2 | 45 | int connect( unsigned int ip_addr, unsigned short port ); |
kishino | 4:99cc93fe7d88 | 46 | |
kishino | 4:99cc93fe7d88 | 47 | /** Check if the socket is connected |
kishino | 12:0254eaccfda2 | 48 | @return true if connected, false otherwise. |
kishino | 4:99cc93fe7d88 | 49 | */ |
kishino | 4:99cc93fe7d88 | 50 | bool is_connected(void); |
kishino | 4:99cc93fe7d88 | 51 | |
kishino | 4:99cc93fe7d88 | 52 | /** Send data to the remote host. |
kishino | 12:0254eaccfda2 | 53 | @param data The buffer to send to the host. |
kishino | 12:0254eaccfda2 | 54 | @param length The length of the buffer to send. |
kishino | 12:0254eaccfda2 | 55 | @return the number of written bytes on success (>=0) or -1 on failure |
kishino | 4:99cc93fe7d88 | 56 | */ |
kishino | 12:0254eaccfda2 | 57 | int send(unsigned char *data_p, int length); |
kishino | 4:99cc93fe7d88 | 58 | |
kishino | 4:99cc93fe7d88 | 59 | /** Receive data from the remote host. |
kishino | 12:0254eaccfda2 | 60 | @param data The buffer in which to store the data received from the host. |
kishino | 12:0254eaccfda2 | 61 | @param length The maximum length of the buffer. |
kishino | 12:0254eaccfda2 | 62 | @return the number of received bytes on success (>=0) or -1 on failure |
kishino | 4:99cc93fe7d88 | 63 | */ |
kishino | 12:0254eaccfda2 | 64 | int receive(unsigned char *data_p, int length); |
kishino | 4:99cc93fe7d88 | 65 | |
kishino | 4:99cc93fe7d88 | 66 | private: |
kishino | 4:99cc93fe7d88 | 67 | |
kishino | 4:99cc93fe7d88 | 68 | }; |
kishino | 4:99cc93fe7d88 | 69 | } |
kishino | 4:99cc93fe7d88 | 70 | #endif |