ClearCore Library
Loading...
Searching...
No Matches
EthernetTcpClient.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Teknic, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
27#ifndef __ETHERNETTCPCLIENT_H__
28#define __ETHERNETTCPCLIENT_H__
29
30#include <stdint.h>
31#include "EthernetTcp.h"
32#include "IpAddress.h"
33
34namespace ClearCore {
35
39#define TCP_CONNECTION_TIMEOUT_MIN 100
43#define TCP_CONNECTION_TIMEOUT_MAX 15000
44
58class EthernetTcpClient : public EthernetTcp {
59
60public:
61#ifndef HIDE_FROM_DOXYGEN
66
70 explicit EthernetTcpClient(TcpData *tcpData);
71#endif // !HIDE_FROM_DOXYGEN
72
78 bool Connect(IpAddress ip, uint16_t port);
79
86 bool Connected();
87
93 int16_t BytesAvailable();
94
104 int16_t Read();
105
114 int16_t Read(uint8_t *dataPtr, uint32_t length);
115
125 int16_t Peek();
126
133 void Flush();
134
139
143 void Close();
144
155 uint32_t Send(const uint8_t *buff, uint32_t size) override;
156
166 uint32_t Send(uint8_t charToSend) {
167 return EthernetTcp::Send(charToSend);
168 }
169
180 uint32_t Send(const char *nullTermStr) {
181 return EthernetTcp::Send(nullTermStr);
182 }
183
189 uint16_t RemotePort();
190
191 using EthernetTcp::LocalPort;
192
200
206 uint16_t ConnectionTimeout() {
207 return m_connectionTimeout;
208 }
209
220 void ConnectionTimeout(uint16_t timeout);
221
222#ifndef HIDE_FROM_DOXYGEN
223 virtual bool operator == (const EthernetTcpClient);
224#endif // !HIDE_FROM_DOXYGEN
225
226private:
227 uint16_t m_connectionTimeout;
228 bool m_dnsInitialized;
229
230}; // EthernetTcpClient
231
232} // ClearCore namespace
233
234#endif // !__ETHERNETTCPCLIENT_H__
ClearCore TCP client class.
Definition EthernetTcpClient.h:58
uint16_t ConnectionTimeout()
Returns the connection timeout.
Definition EthernetTcpClient.h:206
bool Connected()
Determines if the client is actively connected to a server.
uint32_t Send(uint8_t charToSend)
Send a TCP packet.
Definition EthernetTcpClient.h:166
void ConnectionTimeout(uint16_t timeout)
Set the connection timeout. This is the maximum amount of time to wait for a server to accept this cl...
uint32_t Send(const char *nullTermStr)
Send a TCP packet.
Definition EthernetTcpClient.h:180
uint32_t Send(const uint8_t *buff, uint32_t size) override
Send the buffer contents to the server.
IpAddress RemoteIp()
Returns the remote IP address of the server this client is connected to.
int16_t Read(uint8_t *dataPtr, uint32_t length)
Reads data received from the server.
int16_t BytesAvailable()
Returns the number of bytes available to read.
void Flush()
Wait until all outgoing data to the server has been sent.
uint16_t RemotePort()
Returns the remote port of the server this client is connected to.
bool Connect(IpAddress ip, uint16_t port)
Connects the client to a specified remote IP address and port.
void FlushInput()
Flush the received data.
void Close()
Close the client's connection to the server.
int16_t Read()
Attempt to read the next available character.
int16_t Peek()
Attempt to get the next available character.
An IP Address class.
Definition IpAddress.h:41
Namespace to encompass the ClearCore board API.
Definition AdcManager.h:36