#include <ELClientSocket.h>
Public Member Functions | |
| ELClientSocket (ELClient *e) | |
| Class to send/receive data. | |
| int | begin (const char *host, uint16_t port, uint8_t sock_mode, void(*userCb)(uint8_t resp_type, uint8_t client_num, uint16_t len, char *data)=0) |
| Initialize communication to a remote server. | |
| void | send (const char *data) |
| Send null-terminated data to the remote server. | |
| void | send (const char *data, int len) |
| Send data to the remote server. | |
| uint16_t | getResponse (uint8_t *resp_type, uint8_t *client_num, char *data, uint16_t maxLen) |
| Retrieve response. | |
| uint16_t | waitResponse (uint8_t *resp_type, uint8_t *client_num, char *data, uint16_t maxLen, uint32_t timeout=DEFAULT_SOCKET_TIMEOUT) |
| Wait for the response. | |
Data Fields | |
| int32_t | remote_instance |
Definition at line 40 of file ELClientSocket.h.
| ELClientSocket::ELClientSocket | ( | ELClient * | e | ) |
Class to send/receive data.
The ELClientSocket class sends data over a Socket to a remote server or acts as a TCP socket server. Each instance is used to communicate with one server and multiple instances can be created to send to multiple servers. The ELClientSocket class does not support concurrent requests to the same server because only a single response can be recevied at a time and the responses of the two requests may arrive out of order.
Definition at line 24 of file ELClientSocket.cpp.
| int ELClientSocket::begin | ( | const char * | host, |
| uint16_t | port, | ||
| uint8_t | sock_mode, | ||
| void(*)(uint8_t resp_type, uint8_t client_num, uint16_t len, char *data) | userCb = 0 |
||
| ) |
Initialize communication to a remote server.
begin(const char* host, uint16_t port, uint8_t sock_mode, void (*userCb)(uint8_t resp_type, uint8_t client_num, uint16_t len, char *data))
Initialize communication to a remote server, this communicates with esp-link but does not open a connection to the remote server.
| host | Host to be connected. Can be a URL or an IP address in the format of xxx.xxx.xxx.xxx . |
| port | Port to be used to send/receive packets. Port MUST NOT be 80, 23 or 2323, as these ports are already used by EL-CLIENT on the ESP8266 |
| sock_mode | Set socket mode to SOCKET_TCP_CLIENT, SOCKET_TCP_CLIENT_LISTEN, SOCKET_TCP_SERVER or SOCKET_UDP |
| (*userCb)(uint8_t | resp_type, uint8_t client_num, uint16_t len, char *data) (optional) Pointer to callback function that is called if data after data has been sent, received or if an error occured |
Definition at line 121 of file ELClientSocket.cpp.

| uint16_t ELClientSocket::getResponse | ( | uint8_t * | resp_type, |
| uint8_t * | client_num, | ||
| char * | data, | ||
| uint16_t | maxLen | ||
| ) |
Retrieve response.
getResponse(uint8_t resp_type, uint8_t *client_num, char data, uint16_t maxLen)
Check if a response from the remote server was received, returns the number of send or received bytes, 0 if no response (may need to wait longer)
| resp_type | Pointer to response type. Is USERCB_SENT if packet was sent or USERCB_RECV if a packet was received. |
| client_num | Pointer to connection number. Can be used to distinguish between different socket clients. |
| data | Pointer to buffer for received packet |
| maxLen | Size of buffer for received packet. If the received packet is larger than the buffer, the received packet will be truncated. |
uint16_t Size of received packet or number of sent bytes or 0 if no response Definition at line 236 of file ELClientSocket.cpp.

| void ELClientSocket::send | ( | const char * | data | ) |
Send null-terminated data to the remote server.
| data | Pointer to SOCKET packet, must be null-terminated |
Definition at line 184 of file ELClientSocket.cpp.


| void ELClientSocket::send | ( | const char * | data, |
| int | len | ||
| ) |
Send data to the remote server.
send(const char* data, int len)
| data | Pointer to SOCKET packet |
| len | Length of SOCKET packet |
Definition at line 160 of file ELClientSocket.cpp.

| uint16_t ELClientSocket::waitResponse | ( | uint8_t * | resp_type, |
| uint8_t * | client_num, | ||
| char * | data, | ||
| uint16_t | maxLen, | ||
| uint32_t | timeout = DEFAULT_SOCKET_TIMEOUT |
||
| ) |
Wait for the response.
waitResponse(uint8_t resp_type, uint8_t *client_num, char data, uint16_t maxLen, uint32_t timeout)
Checks if a response from the remote server has arrived for timeout seconds, returns the number of send or received bytes, 0 if no response (may need to wait longer)
| resp_type | Pointer to response type. Is USERCB_SENT if packet was sent or USERCB_RECV if a packet was received. |
| client_num | Pointer to connection number. Can be used to distinguish between different socket clients. |
| data | Pointer to buffer for received packet |
| maxLen | Size of buffer for received packet. If the received packet is larger than the buffer, the received packet will be truncated. |
| timeout | (optional) Timout in milli seconds to wait for a response, defaults to 5000ms |
uint16_t Size of received packet or number of sent bytes or 0 if no response Definition at line 306 of file ELClientSocket.cpp.

| int32_t ELClientSocket::remote_instance |
Connection number, value can be 0 to 3
Definition at line 71 of file ELClientSocket.h.