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
54class EthernetTcpClient : public EthernetTcp {
55
56public:
57#ifndef HIDE_FROM_DOXYGEN
62
66 explicit EthernetTcpClient(TcpData *tcpData);
67#endif // !HIDE_FROM_DOXYGEN
68
74 bool Connect(IpAddress ip, uint16_t port);
75
82 bool Connected();
83
89 int16_t BytesAvailable();
90
100 int16_t Read();
101
110 int16_t Read(uint8_t *dataPtr, uint32_t length);
111
121 int16_t Peek();
122
129 void Flush();
130
135
139 void Close();
140
151 uint32_t Send(const uint8_t *buff, uint32_t size) override;
152
162 uint32_t Send(uint8_t charToSend) {
163 return EthernetTcp::Send(charToSend);
164 }
165
176 uint32_t Send(const char *nullTermStr) {
177 return EthernetTcp::Send(nullTermStr);
178 }
179
185 uint16_t RemotePort();
186
187 using EthernetTcp::LocalPort;
188
196
202 uint16_t ConnectionTimeout() {
203 return m_connectionTimeout;
204 }
205
216 void ConnectionTimeout(uint16_t timeout);
217
218#ifndef HIDE_FROM_DOXYGEN
219 virtual bool operator == (const EthernetTcpClient);
220#endif // !HIDE_FROM_DOXYGEN
221
222private:
223 uint16_t m_connectionTimeout;
224 bool m_dnsInitialized;
225
226}; // EthernetTcpClient
227
228} // ClearCore namespace
229
230#endif // !__ETHERNETTCPCLIENT_H__
ClearCore TCP client class.
Definition EthernetTcpClient.h:54
uint16_t ConnectionTimeout()
Returns the connection timeout.
Definition EthernetTcpClient.h:202
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:162
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:176
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